如何以编程方式检测和定位 Windows 10 SDK? [英] How to programmatically detect and locate the Windows 10 SDK?

查看:81
本文介绍了如何以编程方式检测和定位 Windows 10 SDK?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有 Windows 注册表项(或其他易于编程的方式)来查找 &检测适用于 SDK V10.0 的 Windows SDK?

Is there a Windows registry key (or other easily-programmable way) to find & detect the Windows SDK, which works for SDK V10.0?

我正在做类似于这个的事情,ie 使用 Windows 10 SDK 附带的一些工具.

I am doing something similar to this, i.e. making use of some of the tooling accompanying the Windows 10 SDK.

我正在寻找一种程序方式来检测和定位 Windows SDK.此技术必须适用于(至少)版本 10.0(截至此问题的当前版本).最好,我想要一种适用于所有版本的技术(世界和平也会很好).

I am looking for a programatic way to detect and locate the Windows SDK. This technique must work for (at least) version 10.0 (current as of this question). Preferably, I would like a technique that works for all versions (and world peace would be nice too).

以前的版本(至少到 V8.1A - 包含在 VisualStudio 2013) 可通过 Windows 注册表检测到.(虽然 V<7.0 可能没有).

Previous versions (at least up to V8.1A - as was included with Visual Studio 2013) were detectable via the windows registry. (Although V<7.0 may not have been).

对于 64 位安装:HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Microsoft SDKs\Windows(注意与 32 位的粗体区别).

For 64-bit installations: HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Microsoft SDKs\Windows (note the bolded difference from 32-bit).

对于 32 位安装:HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SDKs\WindowsHKEY_CURRENT_USER\SOFTWARE\Microsoft\Microsoft SDKs\Windows

While for 32-bit installs: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SDKs\Windows, and HKEY_CURRENT_USER\SOFTWARE\Microsoft\Microsoft SDKs\Windows

(在 MSDN Windows SDK 博客).

但是,V10.0(或 Visual Studio 2015 中包含的 V10.0A)不会像以前的版本那样创建注册表项!

However, V10.0 (or V10.0A as is included with Visual Studio 2015) does not make a registry key as did previous versions!

有技术使用编译器宏 检测 SDK 版本.但是,这些仅用于 SDK 工具(xsd.exe 等)并不实用,因为它们需要整个编译步骤 - 并且这不一定会生成 SDK 工具目录的路径!

There are techniques using compiler macros to detect the SDK version. However, these are not practical simply for SDK tool use (xsd.exe, etc), as they would require an entire compilation step - AND this would not necessarily yield a path to the SDK's tool directory!

理想情况下,这应该可以使用 PowerShell 或批处理脚本或其他一些可以包含在构建脚本或其他自动化环境中的简单方法来实现(毕竟它们是编程工具).

Ideally, this should be achievable using PowerShell or a batch script or some other simple means that can be included in a build script or other automated environment (they are programming tools after all).

,有多种方法可以通过询问文件系统(以编程方式列出子目录的 %ProgramFiles(x86)%\Microsoft SDKs\Windows\,解析出 'V' 和 'A'-s 并选择列出的数字的 max()(10.0 等)...

Yes there are ways to do this by interrogating the file-system, (i.e. programmatically listing subdirectories of %ProgramFiles(x86)%\Microsoft SDKs\Windows\, parsing out the 'V' and 'A'-s and selecting the max() of the numbers listed (10.0, etc)...

然而,这些方法有许多缺点:

HOWEVER, these approaches have a number of drawbacks:

  1. 相当笨重(文件系统访问、字符串解析等)
  2. 容易出错,错误卸载的 SDK 留下的空文件夹可能会阻止上述笨重的目录解析.
  3. 受路径差异的影响,按平台(ie %ProgramFiles(x86)% 在 x64 上,但 %ProgramFiles% 在 32 位上),并按 SDK 版本;SDK<7 将工具定位在 Bin 目录中,而 SDK>7 使用 bin\NETFX XX 工具(注意小写的b",只是为了增加不一致).立>
  4. 还取决于用户安装选择(例如,聪明的"系统管理员将 SDK 安装在 C:\Stuff\WinSDK\V10.0\ 中).
  1. Quite clunky (filesystem access, string parsing, etc)
  2. Error prone, an empty folder leftover from an incorrectly uninstalled SDK could brake said clunky directory parsing.
  3. Subject to path differences, by platform (i.e. %ProgramFiles(x86)% on x64, but %ProgramFiles% on 32-bit), and by SDK version; SDK<7 locates tooling inside a Bin directory, while SDK>7 uses bin\NETFX X.X tools (note the lowercase 'b', just for added inconsistency).
  4. Also subject to user installation choices ("clever" sys admin installed the SDK in C:\Stuff\WinSDK\V10.0\, for example).

因此以编程方式实现这一点会很多更好,例如通过注册表(可能适用于以前的 Windows SDK 版本)

Hence it would be MUCH better to achieve this programmatically, such as via the registry (as is possible for previous Windows SDK versions)

这个问题不是 这个,因为这个问题既询问不同的SDK版本,也询问程序化(> 注册表等)找到 SDK 路径的方法.

This question is not a duplicate of this one, as this question is both asking about a different SDK version, and is also asking about a programmatic (i.e. registry, etc) way to find the SDK path.

它也不是这个的副本,作为那个问题 专门处理 cmake 并涉及内部版本号不匹配.

Nor is it a duplicate of this, as that question was dealing specifically with cmake and involved a build-number mismatch.

推荐答案

我没有它的权威来源,但它追溯到 Windows 10 SDK 的卸载程序,并在几台机器上检查出来我看了:

I don't have an authoritative source for it, but it traces back from the uninstaller of the Windows 10 SDK, and it checked out on a couple of machines I looked at:

HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows Kits\Installed Roots
KitsRoot10="C:\Program Files (x86)\Windows Kits\10\"

确切的版本有点难以猜测,因为例如 10.0.10150.010.0.10240.010.0.10586.0 都是C:\Program Files (x86)\Windows Kits\10\Include 下的子目录.

The exact version is a bit trickier to guess, since for example 10.0.10150.0, 10.0.10240.0 and 10.0.10586.0 are all subdirectories under C:\Program Files (x86)\Windows Kits\10\Include.

这篇关于如何以编程方式检测和定位 Windows 10 SDK?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆