问题
I have a project created in Visual Studio, 2013.
The project file has the following properties:
ToolsVersion="12.0", PlatformToolset = v120.
I have Visual Studio 2013 and Microsoft Build Tools 2015 installed. This project gets successfully built using MSBuild 12.0. Upon the attempt to build it with MSBuild 14.0 I get an error
MSB4019: The imported project "C:\Microsoft.Cpp.Default.props" was not found. Confirm that the path in the <Import> declaration is correct, and that the file exists on disk.
As I understand, the problem is that the variable VCTargetsPath doesn’t get evaluated. If I specify the variable VCTargetsPath before the build (with the value C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120), the problem is solved.
However, this approach is not very convenient in case the path is different. Is it possible to somehow solve the problem in a more optimal way?
The registry key and its value:
HKLM\Software\WOW6432Node\Microsoft\MSBuild\ToolsVersions\12.0\VCTargetsPath $([MSBuild]::ValueOrDefault('$(VCTargetsPath)','$(MSBuildExtensionsPath32)\Microsoft.Cpp\v4.0\V120\'))
回答1:
It took me two hours to fix this problem, but I finally finished.
The following solved my problem:
- Run this on an elevated command prompt (admin):
npm install --global --production windows-build-tools. If you don't have npm I recommend installing it, otherwise this won't work. - Change ownership in the install dir (in my case
C:\Program Files (x86)\MSBuild\14.0) to your user, instead of admin. (properties>Security>Advanced).
回答2:
I recently reinstalled Visual studio 2017 and encountered this issue while trying to install "npm java". The fix for me is:
- set ms version to 2017:
npm config set msvs_version 2017 - set VCTargetsPath environment variable to
C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\Common7\IDE\VC\VCTargets - run command console as system administrator
回答3:
These steps solved my issue:
- Run
npm install --global --production windows-build-tools - Run
npm install --save nan - Set
VCTargetsPathenvironment variable toC:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140
回答4:
For those the above answer does not work, here is another possible solution to look at.
Even the installation of build tools or VS 2015 did not work for me. So I tried installing below directly via PowerShell (as admin)
https://chocolatey.org/packages/visualcpp-build-tools/14.0.25420.1 Command: choco install visualcpp-build-tools --version 14.0.25420.1
Once this was installed, set an environment variable VCTargetsPath=C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\v140
回答5:
I solved this by:
- Set
VCTargetsPathenvironment variable toC:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140 - build using admin
回答6:
For those using VS 2019:
set VCTargetsPath=C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Microsoft\VC\v160
回答7:
I tried npm install and VCTargetsPath, all not work. Finally solved after it after upgrading visual studio to the latest version.
回答8:
Resolved by installing Visual Studio Express 2015 for Windows 10.
回答9:
Make sure to use --global with the command in order to be able to use this package anywhere. This solves the issue for me
来源:https://stackoverflow.com/questions/41695251/c-microsoft-cpp-default-props-was-not-found