3

Currently we are using (git) Bitbucket as source control, and Bamboo for build and deployment.

One of our projects is a legacy .NET Framework 4.7.2 MVC application. Some projects in that solution were once migrated to netstandard2.0. So the main MVC project is .NET Framework 4.7.2, and all the others projects in the solution are either also .NET Framework 4.7.2, or netstandard2.0.

Visual Studio (2019) has no problems building and running the entire solution. And Bamboo has no problems building and deploying the solution as well. Bamboo builds with MSBuild.

But when I use the same MSBuild configuration in Azure DevOps, then I get build errors. I guess because of the mix of .NET SDK versions in the project.

My azure-pipelines.yml looks like this:

trigger:
- master

pool:
  # also tried VS2019, but got same errors during build
  vmImage: 'VS2017-Win2016'

variables:
  solution: 'WebSolution.sln'
  buildPlatform: 'Any CPU'
  buildConfiguration: 'Release'

steps:
- task: NuGetToolInstaller@1

- task: NuGetCommand@2
  inputs:
    restoreSolution: '$(solution)'

- task: VSBuild@1
  inputs:
    solution: '$(solution)'
    msbuildArgs: '/p:Configuration=web-develop /p:DeployOnBuild=false /p:PublishProfile=web.pubxml /p:AllowUntrustedCertificate=True'
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'

- task: PublishBuildArtifacts@1
  inputs:
    PathtoPublish: '$(Build.ArtifactStagingDirectory)'
    ArtifactName: 'drop'
    publishLocation: 'Container'

But why on Azure DevOps is it complaining about the mix of the SDK frameworks? Why is Visual Studio and Bamboo able to build the solution without any issue?

A compatible SDK version for global.json version: [2.0.2] from [D:\a\1\s\global.json] was not found
##[error]C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Sdks\Microsoft.NET.Sdk\build\Microsoft.NET.TargetFrameworkInference.targets(126,5): Error : The current .NET SDK does not support targeting .NET Standard 2.0.  Either target .NET Standard 1.6 or lower, or use a version of the .NET SDK that supports .NET Standard 2.0.
Project "D:\a\1\s\WebSolution.Bc.Common\WebSolution.Bc.Common.csproj" (2) is building "D:\a\1\s\Web.WebData\Web.WebData.csproj" (4:2) on node 1 (default targets).
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Sdks\Microsoft.NET.Sdk\build\Microsoft.NET.TargetFrameworkInference.targets(126,5): error : The current .NET SDK does not support targeting .NET Standard 2.0.  Either target .NET Standard 1.6 or lower, or use a version of the .NET SDK that supports .NET Standard 2.0. [D:\a\1\s\Web.WebData\Web.WebData.csproj]

Is there a way to fix this in DevOps without having migrate every project in the solution to .NET Core?

Vivendi
  • 20,047
  • 25
  • 121
  • 196

1 Answers1

1

I was facing a similar issue mixing .net standard 2.1 and dotnet 6 in a test pipeline. I didn't even get an error in the inital test pipeline... it just failed like... "Hey I could execute everything, but I doubt you want me to succeed". Anyway... it turned out to be the nuget package manager, which was complaining that some of the nugets in the solution are not compatible with every project in the solution

Heres what i did to fix it:

trigger:
- master

pool:
  vmImage: windows-latest

steps:
#specify the nuget tool
- task: NuGetToolInstaller@0
  inputs:
    versionSpec: '5.x' 
  displayName: 'Use latest NuGet 5'

#restore the nuget packages manually
- task: NuGetCommand@2
  inputs:
    command: 'restore'
    restoreSolution: '**/*.sln'
    noCache: true
  displayName: 'Restore NuGet Packages'

#specify the dotnet sdk manually
- task: UseDotNet@2
  inputs:
    packageType: 'sdk'
    version: '6.x'
  displayName: 'Use latest dotnet 6'

#start your actual pipeline
- task: DotNetCoreCLI@2
  inputs:
    command: 'build'
    projects: '**/*.csproj'
  displayName: 'Build Solution'

- task: DotNetCoreCLI@2
  inputs:
    command: 'test'
    testRunTitle: 'Testing'
    projects: '**/*.csproj'
  displayName: 'Executing Unittests'

I know its been a long time but i still hope this helps someone out there.

Canabale
  • 157
  • 1
  • 7