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 framwework 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): errorMSB4019: The imported project "C:\Microsoft.Cpp.Default.props" was notfound. Confirm that the expression in the Import declaration"\Microsoft.Cpp.Default.props" is correct, and that the file exists ondisk.
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.