发生了什么事
WindowsSdkDir
是一个 Visual Studio 内部变量,它基于“平台工具集”项目属性(在“配置属性 / 一般”下)的注册表键派生而来。对于“Visual Studio 2012 (v110)”平台工具集,注册表键如下:
HKLM\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v8.0
HKCU\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v8.0
HKLM\SOFTWARE\Wow6432Node\Microsoft\Microsoft SDKs\Windows\v8.0
HKCU\SOFTWARE\Wow6432Node\Microsoft\Microsoft SDKs\Windows\v8.0
无论 CurrentVersion
和 CurrentInstallFolder
键如何,都会被使用。
如何在 Visual Studio 2012 中使用 Windows 8.1 SDK
如此描述在这篇博客中:
VS 2010/2012 用户: 您可以使用属性表技术为 Windows 8.1 SDK 创建项目,这在这个Visual C++ Team 博客文章中为 VS 2010+Windows 8.0 SDK 原始提出。对于 VS 2010,只需将路径部分的 "8.0"/"win8" 更改为 "8.1"/"winv6.3" ,然后使用所有这些说明。对于 VS 2012,您可以简化所有路径,只需在每个变量的现有值之前添加 8.1 路径即可。更新的 .props 文件附在本博客中。这仅适用于 Win32 桌面应用程序开发。
进行这些更改后,对于 x86,您应该可以获得一个属性表(也作为同一篇博客的附件):
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ImportGroup Label="PropertySheets" />
<PropertyGroup Label="UserMacros" />
<PropertyGroup>
<ExecutablePath>$(ProgramFiles)\Windows Kits\8.1\bin\x86;$(ExecutablePath)</ExecutablePath>
<IncludePath>$(ProgramFiles)\Windows Kits\8.1\Include\um;$(ProgramFiles)\Windows Kits\8.1\Include\shared;$(ProgramFiles)\Windows Kits\8.1\Include\winrt;$(IncludePath)</IncludePath>
<LibraryPath>$(ProgramFiles)\Windows Kits\8.1\lib\winv6.3\um\x86;$(LibraryPath)</LibraryPath>
<ExcludePath>$(ProgramFiles)\Windows Kits\8.1\Include\um;$(ProgramFiles)\Windows Kits\8.1\Include\shared;$(ProgramFiles)\Windows Kits\8.1\Include\winrt;$(ExcludePath)</ExcludePath>
</PropertyGroup>
<ItemDefinitionGroup />
</Project>
同样适用于x64:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ImportGroup Label="PropertySheets" />
<PropertyGroup Label="UserMacros" />
<PropertyGroup>
<ExecutablePath>$(ProgramFiles)\Windows Kits\8.1\bin\x64;$(ExecutablePath)</ExecutablePath>
<IncludePath>$(ProgramFiles)\Windows Kits\8.1\Include\um;$(ProgramFiles)\Windows Kits\8.1\Include\shared;$(ProgramFiles)\Windows Kits\8.1\Include\winrt;$(IncludePath)</IncludePath>
<LibraryPath>$(ProgramFiles)\Windows Kits\8.1\lib\winv6.3\um\x64;$(LibraryPath)</LibraryPath>
<ExcludePath>$(ProgramFiles)\Windows Kits\8.1\Include\um;$(ProgramFiles)\Windows Kits\8.1\Include\shared;$(ProgramFiles)\Windows Kits\8.1\Include\winrt;$(ExcludePath)</ExcludePath>
</PropertyGroup>
<ItemDefinitionGroup />
</Project>
请注意,这里有一个警告。尽管这将定义构建对Windows 8.1 SDK所需的所有路径,但它不会更改
WindowSdkDir
和相关宏,这些宏仍然指向Windows 8.0 SDK。如果您使用这些宏来定义项目属性,可能会导致构建不一致。
最后,请注意Visual Studio 2013附带Windows 8.1 SDK,并相应地是默认的“Visual Studio 2013(v120)”平台工具集属性所使用的SDK。因此,如果升级到VS2013是一个选择,那么可能会为您节省一些麻烦。