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

Visual StudioVisual Studio-2012Msbuild

Visual Studio Problem Overview


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\'))

Visual Studio Solutions


Solution 1 - Visual Studio

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 - Visual Studio

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 - Visual Studio

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 - Visual Studio

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 - Visual Studio

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

Solution 6 - Visual Studio

I solved this by:

  1. Set VCTargetsPath environment variable to C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140
  2. build using admin

Solution 7 - Visual Studio

I could not make it work with all the suggestions on this page

I downgraded nodejs to 10.15 and it worked fine

probably not the best answer but it works

Solution 8 - Visual Studio

When running MSBuild outside of Visual Studio 2019 (migrated from 2012), I had these kinds of problems. I solved them running this MSBuild:

"C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\msbuild"

(customize it based on your VS version and target architecture) instead of this one:

C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild

that I was using when I had Visual Studio 2012.

Solution 9 - Visual Studio

I tried npm install and VCTargetsPath, all not work. Finally solved after it after upgrading visual studio to the latest version.

Solution 10 - Visual Studio

Resolved by installing Visual Studio Express 2015 for Windows 10.

Solution 11 - Visual Studio

I solved the problem by loading the solution in VS 2019 instead of double-clicking the solution name in File Explorer.

Solution 12 - Visual Studio

This happened for me when I used node version 14.15.3, install Node Version Manager, install lower Node version (8.x.x for example), switch to it and that should solve the issue.

Solution 13 - Visual Studio

After calling VS2019's vcvarsall.bat, it is necessary to use VS2019's MSBuild instead of the one in C:\Windows.

set VCVARSALL=%ProgramFiles(x86)%\Microsoft Visual Studio\2019\Professional\VC\Auxiliary\Build\vcvarsall.bat
call "%VCVARSALL%" amd64
set MSBUILD=%ProgramFiles(x86)%\Microsoft Visual Studio\2019\Professional\MSBuild\Current\Bin\MSBuild.exe
rem set MSBUILD=%FrameworkDir%\%FrameworkVersion%\msbuild.exe

Solution 14 - Visual Studio

In my case, the reason was that the system environment variable VisualStudioVersion was pointing to the removed version of Visual Studio.

The same solution was building ok from inside the Visual Studio but failed when building with the command-line MSBuild.

The problem was solved by changing the environment variable manually.

Solution 15 - Visual Studio

I have VS 2019 and I met the same problem trying to install module 'keytar' on Windows 10. This is what I did in order to solve the problem:

  1. Opened "Visual Studio Installer" and removed extra 2017/2019 build tools (for example "Visual Studio Build Tools 2017", restarted the PC
  2. Got back into "Visual Studio Installer" / "Visual Studio Professional 2019" / "Modify" and added "Desktop development with C++" workload
  3. Got into project folder with my problem, removed node_modules folder
  4. Opened CMDO
  5. As @TheRennen suggested performed the command: set VCTargetsPath=C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Microsoft\VC\v160\ (without quotation marks and with one backslash at the end)
  6. run yarn command and now there were no errors.

I think now it a time to add VCTargetsPath into Windows env values.

node v14.19.0, npm 7.20.5, yarn 1.22.15

Solution 16 - Visual Studio

I have faced this issue while building my flutter application. The issue arises because of the program in my case flutter was unable to locate the file "Microsoft.Cpp.Default.props" which is required for building flutter apps in windows.

For solving the issue install MicroSoft Visual Studio(not Visual Studio code) from the below url. https://visualstudio.microsoft.com/downloads/

Make sure to check the below option before starting installation.

After installation go to below directory.

C:\Program Files\Microsoft Visual Studio\2022\Community\Msbuild\Microsoft\VC

Note : I have installed community version of 2022 Visual Studio. The folder structure may be different based on your VS version

You can see few folders with version numbers

Open the folder and check which one have the "Microsoft.Cpp.Default.props" file . For my case it was the last folder v170. Open Environment variable and set "VCTargetsPath" variable with path to the folder in which "Microsoft.Cpp.Default.props" is present. Save path and restart the build process. This should work.

Solution 17 - Visual Studio

Make sure to use --global with the command in order to be able to use this package anywhere. This solves the issue for me

Solution 18 - Visual Studio

While checking the .vcxproj file, I noticed the ToolsVersion was missing. I added it and it solves the issue.

Before :

<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

After :

<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionSergView Question on Stackoverflow
Solution 1 - Visual StudioNic SzermanView Answer on Stackoverflow
Solution 2 - Visual StudioAlexView Answer on Stackoverflow
Solution 3 - Visual StudioEmre TapcıView Answer on Stackoverflow
Solution 4 - Visual StudioTheRennenView Answer on Stackoverflow
Solution 5 - Visual StudioSorabh MendirattaView Answer on Stackoverflow
Solution 6 - Visual StudioPytLabView Answer on Stackoverflow
Solution 7 - Visual Studiophil123456View Answer on Stackoverflow
Solution 8 - Visual StudiobluishView Answer on Stackoverflow
Solution 9 - Visual StudioPaaSFlyView Answer on Stackoverflow
Solution 10 - Visual StudioPatapoomView Answer on Stackoverflow
Solution 11 - Visual StudiogerritvnView Answer on Stackoverflow
Solution 12 - Visual StudioLuka DevicView Answer on Stackoverflow
Solution 13 - Visual StudioSteve MitchellView Answer on Stackoverflow
Solution 14 - Visual StudioMikhail VorotilovView Answer on Stackoverflow
Solution 15 - Visual StudioKEMBLView Answer on Stackoverflow
Solution 16 - Visual StudioLivin SunnyView Answer on Stackoverflow
Solution 17 - Visual StudioKareem KhaleelView Answer on Stackoverflow
Solution 18 - Visual StudioGinoDevView Answer on Stackoverflow