azure - 为什么 C :\Program Files\dotnet\sdk\3. 1.201 中缺少 msbuild.exe?导致 AzureDevOps 构建步骤失败

标签 azure azure-devops

我有一个非常简单的 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 tasksolution 参数指定 solutionsprojects

因为您的解决方案中有 .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/

相关文章:

angular - 如果我们使用带有 Angular 的第三方目录服务器(如 Azure),我们可以跳过 keycloak 登录页面吗?

sql-server - 如何归档存储在 SQL Server 中的文档

c# - 如何在 Azure 中为 .NEt 核心应用程序应用 woff 字体?

azure - 如何使用阶段/资源从同一组织内的不同项目触发Azure DevOps管道?

azure - Windows Azure 存储模拟器的错误日志存储在哪里?

javascript - createBlockBlob 和 commitBlobBlocks 在 BlobStorage 中创建空文件

使用 VSTS 进行 NuGet 自动版本控制

c# - Azure DevOps OAuth enpoint 始终返回错误=InvalidScope

azure - 通过azure pipeline单阶段将包部署到多个webapp服务

azure - 向市场添加了新的 VSTS 扩展,能够安装该扩展但未显示在 azure pipeline 任务中