Reputation: 4503
We have a .Net 6 application (api) which we are trying to setup in Azure Pipeline, the yaml file is below.
Whenever we build we get the below error:
##[warning]Unable to find MSBuild version '17.0' for architecture 'x86'. Falling back to version '16.0'.
"C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\MSBuild\Current\Bin\msbuild.exe" "C:\agent\_work\2\s\App.sln"
##[error]TATSP.API\App.API.csproj(0,0): Error MSB4236: The SDK 'Microsoft.NET.Sdk.Web' specified could not be found.
this is also causing it to use VS 2019, speaking with the team who manage the agents for our company they said they did not install VS 2022, but did install .Net 6. Is there anyway to get the build to install MsBuild 17 or is that something the team which manages the agents need to do?
yaml:
trigger:
- main
pool:
name: Company Build
vmImage: 'windows-latest'
variables:
solution: '**/*.sln'
buildPlatform: 'Any CPU'
buildConfiguration: 'Release'
steps:
- task: UseDotNet@2
displayName: 'Use .NET Core runtime 6.0'
inputs:
packageType: runtime
version: 6.x
- task: NuGetToolInstaller@1
displayName: 'Use NuGet 6.3.0'
inputs:
versionSpec: 6.3.0
- task: MSBuild@1
displayName: 'Build solution **/*.sln'
inputs:
solution: '$(solution)'
msbuildVersion: "17.0"
msbuildArguments: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactStagingDirectory)"'
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
- task: VSTest@2
inputs:
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
Upvotes: 1
Views: 2748
Reputation: 5182
I had this issue before, and I solved it by changing the value of buildPlatform
from Any CPU
to x64
.
If the above method doesn't help, I suggest you run msbuild locally to check whether it is a issue from agent machine or pipeline. Here are the detailed steps:
In the machine that you run as agent, go to your msbuild directory. Usually, it is in C:\Program Files (x86)\Microsoft Visual Studio\2019\{version}\MSBuild\Current\Bin
.
{Version}
: Community
, Professional
, or Enterprise
Copy your project to that directory.
Run the following script
msbuild {relative path of the csproj file} -p:DeployOnBuild=true -p:WebPublishMethod=Package -p:PackageAsSingleFile=true -p:SkipInvalidConfigurations=true -p:PackageLocation="{a path on your machine}"
For example:
msbuild WebApplication\WebApplication.csproj -p:DeployOnBuild=true -p:WebPublishMethod=Package -p:PackageAsSingleFile=true -p:SkipInvalidConfigurations=true -p:PackageLocation="D:\packages"
Upvotes: 2