Visual Studio: Fixing Broken $(WindowsSdkDir) Variable
If you get weird errors in Visual Studio that basically state files like Windows.h cannot be found, the reason may be a missing or incorrect WindowsSdkDir variable.
In my case, working with Visual Studio 2008 SP1 (32 bit) on Windows 7 x64 (64 bit) everything was fine until I installed the Windows 7 SDK. After that, no SDK files could be found any more and nothing would compile. Uninstalling the SDK (which I did not really need anyway – I had installed it only to get at XPerf) did not help. After some research, I found out that the Visual Studio internal variable WindowsSdkDir (which is not an environment variable) was missing from the registry. After adding the following, everything worked like a charm again:
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Microsoft SDKs\Windows\CurrentInstallFolder=C:\Program Files\Microsoft SDKs\Windows\v6.0A
[REG_SZ]
Depending on your configuration you might have to set the variable in the user profile instead:
HKEY_CURRENT_USER\SOFTWARE\Wow6432Node\Microsoft\Microsoft SDKs\Windows\CurrentInstallFolder=C:\Program Files\Microsoft SDKs\Windows\v6.0A
[REG_SZ]
5 Comments
Starting from SDK 7.1 there is tool:
“C:\Program Files\Microsoft SDKs\Windows\v7.1\Setup\WindowsSdkVer.exe”
that can be used for changing current version of SDK.
While our old systems continue to build our code just fine, I have this exact problem on a brand new development system we setup:
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.
1> stdafx.cpp
1>c:\program files (x86)\microsoft visual studio 12.0\vc\atlmfc\include\afxv_w32.h(25): fatal error C1083: ‘winsdkver.h’: No such file or directory
We get our solutions from our repository, attempt a build, and get the above error on every compile in the solution.
The new system has: Win7 x64; VS2013 w/ sp2.
When I run regedit, I find the entry:
HKLM\software\wow6432Node\Microsoft\microsoft sdks\windows\currentinstallfolder=c:\program files\Microsoft sdks\windows\v6.0a
And this entry is both on the systems that work and the new one that doesn’t.
I went ahead and installed the Win7 SDK v7.1. I ran WindowsSDKVer.exe and saw the above entry displayed. Toggling between the SDK Version, even though our code doesn’t explicitly use anything from it, made no difference.
I opened a command prompt and verified that the system environment variable
WindowsSDKDir
is present and matches the registry. Oddly, on the development system where everything does build, the environment variable points to SDK 8.1. And that system has VS2008, vs2010, vs2012, and VS2013 installed. The new system where I’m having this issue only has VS2013 installed. But given that our code doesn’t explicitly reference in the SDK, I fail to see the significance of any the SDK setting.
The only other difference I’ve found is that when I run a vs2013 Developer Command Prompt on my reference system, the environment variable is present. But when I run the same command on the new system, I don’t see the environment variable defined. But I don’t know whether or not this is significant given that it is present as a system environment variable.
I’m still looking for a solution.
I posted my solution here:
http://social.msdn.microsoft.com/Forums/vstudio/en-US/853aa155-886b-491c-a414-fa4bca50251a/winsdkverh-no-such-file-or-directory?forum=vcgeneral#e5d73ba3-6a88-4ce7-b5f2-86c0e3a56de6
https://social.msdn.microsoft.com/Forums/vstudio/en-US/5b68623a-44d9-49b4-9b1c-c8de5d4919c5/clean-install-of-vs2013-fails-to-build-c-project-error-could-not-find-windowssdkdir-variable?forum=vcgeneral
Clean install of VS2013 fails to build C++ project. Error: Could not find WindowsSDKDir variable from the registry.
Update:
It seems that the problem is that the following three macros are used without being defined:
$(WindowsSDK_ExecutablePath)
$(WindowsSDK_IncludePath)
$(WindowsSDK_LibraryPath)
These are used in Project Properties -> Configuration Properties -> VC++ Directories in the “Executable Directories”, “Include Directories” and “Library Directories” fields, respectively.
If I replace these with:
$(WindowsSdkDir)\Bin
$(WindowsSdkDir)\Include
$(WindowsSdkDir)\Lib
then the project builds and runs.
I don’t want to have to make these changes every time I create a new project, so it would be great if anyone could tell me how to set these macros. Reading around, it seems that this may be possible by modifying
C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\Microsoft.Cpp.Common.props.
Can anyone offer any advice?
120
$(VCInstallDir_120)
$(VSInstallDir_120)
$(WindowsSdkDir_80) <<————– it work for 2010+2012
I solved this problem by installing a Windows SDK from here: https://developer.microsoft.com/en-us/windows/downloads/windows-10-sdk
Installing SDK through VisualStudio installer did roughly nothing and was at most, to yield confusion.
Then, go to VisualStudio: Project > Retartget solution > Choose the SDK
OR Project > Properties (bottom of the list) > General (on the left)> Windows SDK Version > Choose the SDK
I’m using VisualStudio 2019 Preview (v2 I think)
KEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Microsoft SDKs\Windows\CurrentInstallFolder registry has nothing to do with the fix.
It works now and this particular tree has not been changed.