我有一个非常简单的 WPF 项目 (.Net 4.7.2) 和单元测试项目 (MSTest .Net Core),我试图将其构建在 Azure Pipelines 中,但收到以下错误:
2020-05-07T16:41:52.9562570Z C:\Program Files\dotnet\sdk\3.1.201\Microsoft.Common.CurrentVersion.targets(3032,5): error MSB4216: Could not run the "GenerateResource" task because MSBuild could not create or connect to a task host with runtime "CLR4" and architecture "x86". Please ensure that (1) the requested runtime and/or architecture are available on the machine, and (2) that the required executable "C:\Program Files\dotnet\sdk\3.1.201\MSBuild.exe" exists and can be run. [C:\agent_work\4\s\RsSolution4\WpfApp1\WpfApp1.csproj] 2020-05-07T16:41:53.1174401Z ##[error]Error: The process 'C:\Program Files\dotnet\dotnet.exe' failed with exit code 1
我在建议的文件夹中查找了 msbuild.exe,果然它不存在。该路径存在,并且文件夹中有很多文件,只是没有 msbuild.exe。有一个 msbuild.dll。
这是我的 yaml 文件:
trigger:
- master
pool:
name: Default
demands: msbuild
variables:
solution: '**/*.sln'
buildPlatform: 'Any CPU'
buildConfiguration: 'Release'
steps:
- task: DotNetCoreCLI@2
displayName: Restore NuGet
inputs:
command: 'custom'
projects: '**/*.csproj'
custom: 'restore'
- task: MSBuild@1
inputs:
solution: '**/*.sln'
msbuildLocationMethod: 'location'
msbuildLocation: 'C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Current\Bin\msbuild.exe'
configuration: 'Release'
clean: true
- task: DotNetCoreCLI@2
displayName: SSP Automated Testing
inputs:
command: 'test'
projects: '**/*Test*.csproj'
arguments: '--configuration $(buildConfiguration)'
testRunTitle: 'SSP Testing'
最佳答案
看起来像this known issue对于 dotnet 核心。它说在.NET Core上,MSBuild不支持不同架构/运行时版本的任务主机
。
提供的解决方法是将 CurrentArchitecture/CurrentRuntime
添加到 PropertyGroup。看这个similar issue .
<PropertyGroup Condition="'$(MSBuildRuntimeType)' == 'Core' Or '$(TargetFrameworkIdentifier)' != '.NETFramework'">
<GenerateResourceMSBuildArchitecture Condition=" '$(GenerateResourceMSBuildArchitecture)' == '' ">CurrentArchitecture</GenerateResourceMSBuildArchitecture>
<GenerateResourceMSBuildRuntime Condition=" '$(GenerateResourceMSBuildRuntime)' == '' ">CurrentRuntime</GenerateResourceMSBuildRuntime>
</PropertyGroup>
您还尝试仅使用 msbuild 任务来构建所有项目,因为 msbuild 适用于 .net Framework 和 .net core。您可以为 Msbuild task 的 solution
参数指定 solutions
和 projects
。
因为您的解决方案中有 .Net Framework 项目和 .Net Core 项目。我建议使用Nuget恢复任务来恢复解决方案。 Dotnet cli 无法与 .NET Framework 正常工作,这可能无法恢复 .net Framework 项目。
希望以上有帮助!
关于azure - 为什么 C :\Program Files\dotnet\sdk\3. 1.201 中缺少 msbuild.exe?导致 AzureDevOps 构建步骤失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61663658/