0

I am building a Nuget package with Azure Pipelines.

The pipeline is run by a self hosted agent. It works perfectly for pure .NET and .NET framework projects, but I get an error with a (VS2022) solution that contains a C++ project.

The build step completes without errors, but dotnet pack gives the error:

C:\agents\A1_work\72\s\CPPProject\CPPProject.vcxproj(31,3): error MSB4019: The imported project "C:\Microsoft.Cpp.Default.props" was not found. Confirm that the expression in the Import declaration "\Microsoft.Cpp.Default.props" is correct, and that the file exists on disk.

This is the line in CPPProject that gives the error:

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

This is the YAML code for 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" --output "$(Build.ArtifactStagingDirectory)/Package"'

Why do I get this error in dotnet pack when the solution builds without problems? How do I fix it?

If I change the VCTargetsPath environment variable on my build server to point to the VS2022 installation folder, it will affect the other projects that do not use VS2022.

I could maybe use a .props file to override the value, but it seems like a hack.

Rye bread
  • 1,305
  • 2
  • 13
  • 36

1 Answers1

0

As a workaround, I added this parameter -p:VCTargetsPath to 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"'
 

This made the error go away.

Rye bread
  • 1,305
  • 2
  • 13
  • 36