25

I cannot build my project in Visual Studio 2012. The error is:

1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V110\Microsoft.CppBuild.targets(344,5): warning MSB8003: Could not find WindowsSDKDir variable from the registry. TargetFrameworkVersion or PlatformToolset may be set to an invalid version number."

I have installed Windows SDK, and have tried to reinstall and to repair, and have even tried to enter the registry string key "WindowsSDKDir" to the registry. (HKLM/SOFTWARE/Wow6432Node/Microsoft/Microsoft SDKs/v7.1 with value C:\Program Files\Microsoft SDKs\Windows\v7.1).`

Is it a registry issue, or something else? I've tried searching for those registry keys and re-installing my Windows SDK but neither helped.

Christian Stewart
  • 15,217
  • 20
  • 82
  • 139
clashoftornados
  • 251
  • 1
  • 3
  • 4
  • 1
    Was it a Visual Studio 2010 project originally? If so, it might still be set to use the VS2010 toolset in the general tab in Project Properties – The Dark Mar 05 '14 at 06:40
  • No, It is not originally a 2010 project, In fact, I made a new project in VS2012, and it still came up with this error. – clashoftornados Mar 06 '14 at 04:01
  • Check the settings in Project Properties - Configuration Properties - General - Platform Toolset. Make sure it is set to Visual Studio 2012 (or just try changing it to something else). – The Dark Mar 06 '14 at 04:11
  • It was set to visual studio 2012. I switched it to WindowsSDKv7.1 and go this error : "1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\Platforms\Win32\Microsoft.Cpp.Win32.targets(57,5): error MSB6006: "CL.exe" exited with code -1073741515." – clashoftornados Mar 06 '14 at 22:44
  • As it is running from C:\Program Files (x86), possibly the registry settings should start with C:\Program Files (x86)\ rather than C:\Program Files\. This is how mine look because I am using the x86 version. The info you got about the registry might be for the 64 bit version. – The Dark Mar 06 '14 at 23:28
  • I tried changing this information, but I still get the cannot find registry key. I also get "cannot open file 'kernal32.lib' – clashoftornados Mar 07 '14 at 03:38
  • 3
    Why this question does not have accepted answer ? How will it help to others who are having similar issue ? – Rayon Nov 07 '15 at 03:03
  • This question does not have one single accepted answer, because most of the answers are not relevant (e.g., apply to different VS versions) and there are many possible causes of this problem, and the original poster probably doesn't use VS2012 any more. However, each answer is useful and valuable in its specific scenario. – Florian Winter Oct 11 '18 at 14:29

11 Answers11

19

I was trying to get a script to compile for Script Hook V - GTA .NET Library.

I spent about 2 hours trying to figure out why it wouldn't work. Here is how I got it to build:

I right clicked on the project and selected properties:

Step1

Under Configuration Properties -> General -> Platform Toolset

I selected the dropdown and selected the only other one available

(For me it was Visual Studio 2013 - Windows XP (v120_xp))

Platform Toolset

After that I was able to fly my car normally:

Weeee

Hope this helps someone else trying to do the same thing.

user1274820
  • 7,786
  • 3
  • 37
  • 74
  • Why should we select Windows XP even if I am using Windows 10? – Sashank Mar 14 '17 at 12:14
  • 3
    and a crash landing normally, for this kind of car without wings =)) :)) – Dee Jun 07 '17 at 08:09
  • 1
    A key addition, note that only affects Active(DEBUG) on x64. Change the dropdowns at the top to All configurations firstly. – Kevin Apr 10 '18 at 02:29
  • 1
    I feel like I am missing something. What does "fly my car normally" mean, @Sleavely ? – meustrus Jul 11 '19 at 16:26
  • 1
    @meustrus Normally cars don't fly. OPs colloquial use of the word "normally" made me chuckle in 2017. – Sleavely Jul 12 '19 at 11:24
  • 1
    And here I thought there was more to it. Guess the flying car is just what user1274820 was trying to do as a GTA script hook. On that note, I'd guess it needed to be Windows XP for this particular build because that's the SDK that GTA was originally built with? Personally, I had a different problem (with the same error message, thanks Microsoft) that was solved by simply installing the C++ Visual Studio components I didn't realize were missing. – meustrus Jul 15 '19 at 15:28
11

I have been having this issue lately when trying to install certain Node.js packages! I finally fixed it by adding the correct path to the registry variable!

The easiest way to fix it is by setting it with a simple script.

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Microsoft SDKs\Windows]
"CurrentInstallFolder"="C:\\Program Files (x86)\\Windows Kits\\8.1\\"

This should fix it for any Windows 8.1 64-bit users, but if you have your Windows SDK installed in another directory, simply replace C:\Program Files (x86)\Windows Kits\8.1 with your respective directory. Here are a few places you can try:

  • C:\Program Files (x86)\Windows Kits
  • C:\Program Files (x86)\Microsoft SDKs\Windows
  • C:\Program Files (x86)\Microsoft\Microsoft SDKs\Windows

Note: Make sure to append the version as well to the end of the path; for example, 8.1 is at the end of my path. Basically, you need to get the full path to the Windows SDK and not just the folder containing the main folder(s) for the Windows SDK.

CoolOppo
  • 503
  • 9
  • 17
  • 1
    What if you have multiple versions of the Windows SDK and Visual Studio installed, and you are using all of them? What is the `CurrentInstallFolder` (as opposed to the installation folders of all the individual SDK versions in subkeys of this key in the registry)? -- EDIT: Probably https://stackoverflow.com/a/34901806/2279059 is relevant then. – Florian Winter Oct 11 '18 at 14:22
10

I had the same issue with Visual Studio 2013 ( no Service-packs installed ). Apparently during installation it needs an active internet connection or the sdk-path might be missing.

Just go into your control panel / programs / programs & features - and select "Microsoft Visual Studio xxx 2013", right-click-change and then "repair". It will take a few minutes but afterwards the sdk-path is correct.

kalmiya
  • 2,988
  • 30
  • 38
  • Does your recommendation assume you have an internet connection? – Brad B. Jul 03 '17 at 19:13
  • Phew, that's quite a while back I had that issue... I think at the initial time of installing VS2013 I did not have an internet connection - and for some reason that caused the issue... During the repair, don't remember if I had an internet connection... – kalmiya Jul 04 '17 at 12:52
6

As Parvez pointed, New C++ project, then "Install Windows XP support for C++"

enter image description here

osexp2000
  • 2,910
  • 30
  • 29
  • This worked for x64 win10 SP1 VS2017 (v.15.5.2) while SDK 8.1 and 10 where available and SDK7 was absent. – ZF007 Jan 01 '18 at 21:49
  • 1
    Update for Visual Studio 2017: Install is part of the options for Visual C++ inside Visual Studio Installer. Select Modify > Desktop development with C++ > Windows XP support for C++. – J. Titus May 17 '18 at 13:30
  • This answer is only relevant if the target SDK is version 7. But this issue / error message may also occur when targeting version 8.1 or 10, and then this answer is not relevant and would only lead to installing unnecessary bloat. – Florian Winter Oct 11 '18 at 14:25
  • does not work if you haven't got the templates installed - that info is now missing from the answer. – T.S Jun 21 '19 at 08:48
4

Installing Windows SDK v8.1 solved it for me.

3

Try to invoke SetEnv.cmd manually in your command prompt:

call "C:\Program Files\Microsoft SDKs\Windows\v7.1\bin\Setenv.cmd" /Release /x86

OR

call "C:\Program Files\Microsoft SDKs\Windows\v7.1\bin\Setenv.cmd" /Release /x64
Ruslan
  • 199
  • 3
  • 5
2

For myself works this:

Check the value in "your".vcxproj <PlatformToolset>"some version"</PlatformToolset>

I know it is strange but:

I have installed VC2012 and VC2010 and I compile project from 2012 in 2010 with toolset "v110".

Lesanus
  • 21
  • 1
2

I was also facing the same issue.

Installing Windows SDK v8.1 solved it for me.

https://msdn.microsoft.com/en-us/windows/desktop/bg162891.aspx

Pawan Agrawal
  • 412
  • 8
  • 26
2

I had this same problem with VS2012. I had both 2013 and 2012 installed on my machine and experienced the issue after uninstalling VS2013 (which I was not using anymore due to expired license).

The Registry keys linked above did not help me. In my opinion, independently from your VS version, the safest way to address this is to locate the batch file VS uses to load those macros, which seems to be VCVarsQueryRegistry.bat in C:\Program Files (x86)\Microsoft Visual Studio [YOUR_VERSION].0\Common7\Tools.

Look for the variable VS tells it is not defined. You might then find a snippet like:

@set WindowsSdkDir=
@call :GetWindowsSdkDirHelper32 HKLM > nul 2>&1
@if errorlevel 1 call :GetWindowsSdkDirHelper32 HKCU > nul 2>&1
@if errorlevel 1 call :GetWindowsSdkDirHelper64 HKLM > nul 2>&1
@if errorlevel 1 call :GetWindowsSdkDirHelper64 HKCU > nul 2>&1
@exit /B 0

:GetWindowsSdkDirHelper32
@for /F "tokens=1,2*" %%i in ('reg query "%1\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v8.0" /v "InstallationFolder"') DO (
    @if "%%i"=="InstallationFolder" (
        @SET "WindowsSdkDir=%%k"
    )
)
@if "%WindowsSdkDir%"=="" exit /B 1
@exit /B 0

:GetWindowsSdkDirHelper64
@for /F "tokens=1,2*" %%i in ('reg query "%1\SOFTWARE\Wow6432Node\Microsoft\Microsoft SDKs\Windows\v8.0" /v "InstallationFolder"') DO (
    @if "%%i"=="InstallationFolder" (
        @SET "WindowsSdkDir=%%k"
    )
)

Which makes clear that WindowsSdkDir in a 64bit system is set by Registry value SOFTWARE\Wow6432Node\Microsoft\Microsoft SDKs\Windows\v8.0\InstallationFolder in either HKEY_CURRENT_USER or HKEY_LOCAL_MACHINE depending on your configuration.

Neenster
  • 185
  • 1
  • 5
1

I was getting the error mentioned below when I was trying to install oracle driver for nodejs using npm install oracledb. I have Windows 7.1 SP1 and I have installed Visual Studio 2015 community edition.

C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.CppBuild.targets(366,5): warning MSB8003: Could not find WindowsSDKDir variable from the registry. TargetFrameworkVersion or PlatformToolset may be set to an invalid version number.

Installing VC++ compiler as mentioned here resolved the issue for me. For reference here is the action to do.

You need to launch Visual studio, then do: file > new > project, in the window than opened, select "Model > Visual C++" and in the middle of the window you should see a button "install microsoft C++" or something like that, click on it and it will launch the install process for the C++ & Microsoft SDK. Once that's done it will work as expected !

Parvez
  • 631
  • 1
  • 6
  • 19
0

Adding my observations of a similar problem reporting the same error....

If the required SDKs are installed, but the problem persists, try toggling the Platform Toolset under the project's General configuration properties. For example, I changed Visual Studio 2013 (v120) to Visual Studio 2015 (v140). After applying, I reverted the Platform Toolset back to Visual Studio 2013 (v120) which corrected the problem of the missing WindowsSDKDir setting.

On another workstation where the project works, VS2012 is installed. The new workstation without VS2012 complains about the missing WindowsSDKDir setting; although, the Platform Toolset parameter displays Visual Studio 2013 (v120)

bvj
  • 3,294
  • 31
  • 30