Search code examples
.net-coreazure-devopsyamlmsbuild

MSBuild on .NET Core 6.0 throghs an error MSB3971


I need to build a simple .NET Core 6.0 solution via ADO pipelines.

I've written a yml like this:

trigger:
  paths:
    include: 
    - TAF/*

pool:
  vmImage: ubuntu-latest
variables:
  solution: 'TAF/NetTABase.sln'
  buildPlatform: 'Any CPU'
  buildConfiguration: 'Release'
  
steps:
- task: NuGetToolInstaller@1
  displayName: 'NUGet Installer'

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

- task: UseDotNet@2
  displayName: 'Use .NET Core sdk 6.0'
  inputs:
    version: 6.x

- task: MSBuild@1
  displayName: 'Build Test Automation Solution'
  inputs:
    solution: '$(solution)'
    vsVersion: 17.0
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'
    msbuildArgs: '/p:OutDir=$(Build.BinariesDirectory)'

- task: PublishPipelineArtifact@1
  displayName: 'Publish Artifacts to Pipeline'
  inputs:
    targetPath: '$(Build.BinariesDirectory)'
    artifact: 'TA'
    publishLocation: 'pipeline'

But running on ADO pipeline at msbuild task, I get this error:

/usr/lib/mono/msbuild/Current/bin/Microsoft.Common.CurrentVersion.targets(1232,5): error MSB3971: The reference assemblies for ".NETFramework,Version=v6.0" were not found. You might be using an older .NET SDK to target .NET 5.0 or higher. Update Visual Studio and/or your .NET SDK. [/home/vsts/work/1/s/TAF/APICore/APICore.csproj]

Note that .sln is built with no error in the local VS 2022.

Here is what the project file looks like:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="RestSharp" Version="110.2.0" />
    <PackageReference Include="System.Security.Permissions" Version="7.0.0" />
  </ItemGroup>

</Project>

Could anyone suggest a fix for this?


Solution

  • Ther thing that worked for me is replacing MsBuild@1 task with calling dotnet CLI like so

    - script: dotnet build $(solution) --configuration $(buildConfiguration) --output $(Build.BinariesDirectory) --framework net6.0
    

    Even though dotnet build uses MSBuild to build the project MsBuild@1 is not working somehow. Do know why...