.NET Core 6.0 上的 MSBuild 出现错误 MSB3971

问题描述 投票:0回答:1

我需要通过 ADO 管道构建一个简单的 .NET Core 6.0 解决方案。

我写了一个这样的yml:

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'

但是在 msbuild 任务的 ADO 管道上运行时,我收到此错误:

/usr/lib/mono/msbuild/Current/bin/Microsoft.Common.CurrentVersion.targets(1232,5):错误MSB3971:找不到“.NETFramework,Version = v6.0”的参考程序集。您可能正在使用较旧的 .NET SDK 来定位 .NET 5.0 或更高版本。更新 Visual Studio 和/或 .NET SDK。 [/home/vsts/work/1/s/TAF/APICore/APICore.csproj]

注意

.sln
在本地VS 2022中构建没有错误。

项目文件如下所示:

<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>

有人可以建议解决这个问题吗?

.net-core azure-devops yaml msbuild
1个回答
0
投票

对我有用的事情是将 MsBuild@1 任务替换为像这样调用 dotnet CLI

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

即使 dotnet build 使用 MSBuild 来构建项目,MsBuild@1 也无法正常工作。知道为什么吗...

© www.soinside.com 2019 - 2024. All rights reserved.