dotnet pack 读取一个空的 VCTargetsPath

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

我正在使用 Azure Pipelines 构建一个 Nuget 包。

管道由自托管代理运行。 它非常适合纯 .NET 和 .NET 框架项目,但我在包含 C++ 项目的 (VS2022) 解决方案中遇到错误。

构建步骤完成没有错误,但 dotnet pack 给出错误:

C: gents\A1_work:\s\CPPProject\CPPProject.vcxproj(31,3): 错误 MSB4019:导入的项目“C:\Microsoft.Cpp.Default.props”不是 成立。确认导入声明中的表达式 “\Microsoft.Cpp.Default.props”是正确的,并且该文件存在于 磁盘。

这是 CPPProject 中给出错误的行:

<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />

这是 dotnet pack 的 YAML 代码:

- task: DotNetCoreCLI@2
      displayName: 'dotnet pack'
      inputs:
        command: custom
        projects: '$(projectFolder)/${{ parameters.projectName }}.csproj'
        custom: pack
        arguments: '--no-build --configuration Release -p:PackageId=$(packageName) -p:Authors="MyCompany" --output "$(Build.ArtifactStagingDirectory)/Package"'

当解决方案构建没有问题时,为什么我会在 dotnet pack 中收到此错误?我该如何解决?

如果我将构建服务器上的 VCTargetsPath 环境变量更改为指向 VS2022 安装文件夹,它将影响其他不使用 VS2022 的项目。

我也许可以使用 .props 文件来覆盖该值,但它看起来像是 hack。

visual-studio azure-pipelines nuget-package dotnet-tool
1个回答
0
投票

作为解决方法,我将此参数

-p:VCTargetsPath
添加到 dotnet pack:

- task: DotNetCoreCLI@2
      displayName: 'dotnet pack'
      inputs:
        command: custom
        projects: '$(projectFolder)/${{ parameters.projectName }}.csproj'
        custom: pack
        arguments: '--no-build --configuration Release -p:PackageId=$(packageName) -p:Authors="MyCompany" -p:VCTargetsPath="C:\Program Files\Microsoft Visual Studio\2022\Professional\Msbuild\Microsoft\VC\v170\\" --output "$(Build.ArtifactStagingDirectory)/Package"'
 

这使错误消失了。

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