AzurePipeline 失败的原因是:找不到 .NETFramework,Version=v4.6.1 的参考程序集

ree*_*ee6 22 yaml build-server azure-devops azure-pipelines azure-pipelines-yaml

我有一个用于我的构建的 Azure 管道设置。我最近遇到了这个问题,但找不到解决方法:

##[error]C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(1220,5): Error MSB3644: The reference assemblies for .NETFramework,Version=v4.6.1 were not found. To resolve this, install the Developer Pack (SDK/Targeting Pack) for this framework version or retarget your application. You can download .NET Framework Developer Packs at https://aka.ms/msbuild/developerpacks
Run Code Online (Sandbox Code Playgroud)

大约一周前,我们的许多构建都失败了,微软改变了一些东西,我们得到了这样的东西:

[error]C:\Users\VssAdministrator\.nuget\packages\codegeneration.roslyn.buildtime\0.6.1\build\CodeGeneration.Roslyn.BuildTime.targets(73,5): Error CGR1001: CodeGeneration.Roslyn.Tool (dotnet-codegen) is not available, code generation won't run. Please check https://github.com/AArnott/CodeGeneration.Roslyn for usage instructions. 
Run Code Online (Sandbox Code Playgroud)

但是能够通过显式添加一个任务来包含 netcore2.1 sdk 来解决这个问题

##[error]C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(1220,5): Error MSB3644: The reference assemblies for .NETFramework,Version=v4.6.1 were not found. To resolve this, install the Developer Pack (SDK/Targeting Pack) for this framework version or retarget your application. You can download .NET Framework Developer Packs at https://aka.ms/msbuild/developerpacks
Run Code Online (Sandbox Code Playgroud)

现在这个问题已得到解决,我们现在遇到了错误,抱怨找不到 .NET Framework 4.6.1。

无论如何,任何想法发生了什么,这都让我大吃一惊——任何建议或见解都非常感谢。

Jan*_*SFT 29

4.6.1Azure DevOps Microsoft 托管代理已弃用.Net Framework 版本。目前,有两种 Microsoft 托管代理:

windows-2019或者windows-latest:.Net Framework 版本4.7.24.8预安装。此处记录了这一点。

windows-20224.8:预装.Net框架版本。此处记录了这一点。

也就是说,您需要使用自托管代理4.6.1才能在管道中使用.Net框架。

  • vmImage: yml 中的“windows-2019”对我来说适用于 4.6.1,因此无需使用自托管代理。 (5认同)
  • 虽然这大部分是准确的,但您可以更改代理池中 Windows 托管代理的代理规范以运行 Windows-2019,这将解决该问题。这已记录在[此处](https://blog.novacare.no/devops-change-agent-specification-to-windows-latest/) (3认同)

小智 11

从代理池 - 将代理规范从 Window-Latest 更改为 Window-2019 ,看来 MS 对默认代理做了一些更改

管道设置

  • 具体来说,将管道的 azure-pipelines.yml **pool** 配置部分从 `vmImage: 'windows-latest'` 更新为 `vmImage: 'windows-2019'` 解决了我的问题 (8认同)