Reputation: 2715
I have a build which works fine locally (VSCode, .NET Core 3.1.101) but fails with the following message when run in an Azure DevOps Pipeline.
My pipeline is stripped down to the most basic:
trigger:
- master
pool:
vmImage: 'windows-latest'
variables:
solution: '**/*.sln'
buildPlatform: 'Any CPU'
buildConfiguration: 'Release'
steps:
- task: NuGetToolInstaller@1
- task: NuGetCommand@2
inputs:
restoreSolution: '$(solution)'
And that results in this error message:
Version 3.1.101 of the .NET Core SDK requires at least version 16.3.0 of MSBuild. The current available version of MSBuild is 15.9.21.664. Change the .NET Core SDK specified in global.json to an older version that requires the MSBuild version currently available.
I can't find a way to change the version of MSBuild that the pipeline runs and changing to an older version of .NET Core surely defeats the purpose of upgrading?
Is there any way to build a.NET Core 3.1 solution on Azure DevOps?
Upvotes: 1
Views: 2024
Reputation: 40543
You should be able to restore nuget packages, compile nad run unit tests using this YAML
pool:
vmImage: 'windows-latest'
variables:
buildConfiguration: 'Release'
rootDirectory: '$(Build.SourcesDirectory)'
steps:
- task: DotNetCoreCLI@2
displayName: Restore nuget packages
inputs:
command: restore
projects: '**/*.csproj'
workingDirectory: $(rootDirectory)
- task: DotNetCoreCLI@2
displayName: Build
inputs:
command: build
projects: '$(rootDirectory)/*.sln'
arguments: '--configuration $(buildConfiguration)'
# You just added coverlet.collector to use 'XPlat Code Coverage'
- task: DotNetCoreCLI@2
displayName: Test
inputs:
command: test
projects: '*Tests/*.csproj'
arguments: '--configuration $(buildConfiguration) --collect:"XPlat Code Coverage" -- RunConfiguration.DisableAppDomain=true'
workingDirectory: $(rootDirectory)
I assumed that you solution file is in the root directory. If you use global json please set sdk version to 3.1.201
otherwise another steo may be required.
global.json
{
"sdk": {
"version": "3.1.201",
"rollForward": "latestFeature"
}
}
Upvotes: 1
Reputation: 222522
I do not see anywhere you are having the dotnet build task, you need to have the dotnetbuild task with the version configured,
steps:
- task: UseDotNet@2
displayName: ".NET Core 3.1.x"
inputs:
version: '3.1.x'
packageType: sdk
- script: dotnet build --configuration $(buildConfiguration)
displayName: 'dotnet build $(buildConfiguration)'
Refer this article.
Upvotes: 1