"C:\Microsoft.Cpp.Default.props" was not found

131,949

Solution 1

It took me two hours to fix this problem, but I finally finished.

The following solved my problem:

  1. 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.
  2. 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).

Solution 2

I recently reinstalled Visual studio 2017 and encountered this issue while trying to install "npm java". The fix for me is:

  1. set ms version to 2017: npm config set msvs_version 2017
  2. set VCTargetsPath environment variable to C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\Common7\IDE\VC\VCTargets
  3. run command console as system administrator

Solution 3

These steps solved my issue:

  1. Run npm install --global --production windows-build-tools
  2. Run npm install --save nan
  3. Set VCTargetsPath environment variable to C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140

Solution 4

For those using VS 2019:

set VCTargetsPath="C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Microsoft\VC\v160"

Edit (Sep 2020): Sometimes it requires a trailing backslash (as bmiller mentioned below)

Solution 5

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

Share:
131,949

Related videos on Youtube

Serg
Author by

Serg

Updated on April 16, 2022

Comments

  • Serg
    Serg about 2 years

    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\'))
    
  • Dan Atkinson
    Dan Atkinson over 5 years
    Thank you. I just needed to (re)run npm install -g --production windows-build-tools.
  • HarshitMadhav
    HarshitMadhav about 5 years
    @Nic Szer can you explain me the second step? I am unable to understand it.
  • HarshitMadhav
    HarshitMadhav about 5 years
    @NicSzer in my case I am seeing Owner: SYSTEM what should I do?
  • HarshitMadhav
    HarshitMadhav about 5 years
    where is VCTargetsPath located?
  • Nic Szerman
    Nic Szerman about 5 years
    @HarshitAgrawal you need to change who owns the folder such that your user is the owner, not SYSTEM
  • HarshitMadhav
    HarshitMadhav about 5 years
    @NicSzer thanks for the reply. I did that but getting new errors now. This is my first time trying to run react native project on windows. I need some help Can we connect on chatroom of stackoverflow?
  • canmustu
    canmustu almost 5 years
    npm config set msvs_version 2017 this code saved my hours. Thanks.
  • starscream_disco_party
    starscream_disco_party almost 5 years
    @Alex did your VCTargets directory already contain Microsoft.Cpp.Default.Props? I have the directory but that file is missing.
  • Alex
    Alex almost 5 years
    @starscream_disco_party yes, Microsoft.Cpp.Default.Props is already in my VCTargets folder
  • Hammad ul Hasan
    Hammad ul Hasan over 4 years
    Perfect solution
  • Emre Tapcı
    Emre Tapcı over 4 years
    @HarshitAgrawal VCTargetsPath is the name of the environment variable.
  • Sergei Krivonos
    Sergei Krivonos about 4 years
    The 3rd step only needed in my case.
  • Sergei Krivonos
    Sergei Krivonos about 4 years
    Moving from Express to Pro caused the issue in my case. Set VCTargetsPath environment variable to C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140
  • Meir Gabay
    Meir Gabay almost 4 years
    Using Chocolatey solved it for me, I didn't even set the environment variable, it worked out of the box
  • Georgina Davenport
    Georgina Davenport over 3 years
    Same problem as OP in 2020 and running NPM with these arguments does not work for me. It complains various packages have been deprecated (since February 2020). Although the process completes, the problem still persists.
  • bmiller
    bmiller over 3 years
    This worked for me. Note that I also required a trailing backslash on the path, else the build failed looking for specific platform props in a subfolder.
  • Surya Tej
    Surya Tej over 3 years
    How can we install npm if I face the same situation inside a windows container with a base image as mcr.microsoft.com/dotnet/framework/sdk:4.8-windowsservercore‌​-ltsc2019
  • g0rski
    g0rski over 3 years
    Worked for me as well, although you need to make sure you specified proper VS version (in my case it was Community - "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Microsoft\VC\v160"
  • ranka47
    ranka47 about 3 years
    It seems the relevant content is still missing in the answer. Can you edit it and add that?
  • Bruce C
    Bruce C about 3 years
    2 years later and still running into this issue. Buy a new laptop install everything and then spend days fighting this problem. the npm config set msvs_version 2017 was the fix for me
  • The Coder
    The Coder almost 3 years
    Yup Node 10 is fine for me, unfortunately our servers are on node 12 now and node 10 is being depreciated so it's off to Linux for me.
  • Coder0997
    Coder0997 over 2 years
    I was having issues to install [email protected], after running command "npm config set msvs_version 2017" it seems to have solved the problem for me, thanks
  • Mr Patience
    Mr Patience about 2 years
    Also works with VS 2022 <3
  • Lin Song Yang
    Lin Song Yang almost 2 years
    Thx, for VS2022, set VCTargetsPath=C:\Program Files\Microsoft Visual Studio\2022\Professional\Msbuild\Microsoft\VC\v170