.net 运行 MSBuild 无法读取 SDKToolsPath
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2731365/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Running MSBuild fails to read SDKToolsPath
提问by Scott Mayfield
Howdy, I'm having a bit of an issue runnning a NAnt script that used to properly build my .Net 2.0 based website, when compiling with VS2008 and it's associated tools. I've recently upgraded all the project/solution files to VS2010, and now my build fails with the following error:
您好,在使用 VS2008 及其相关工具进行编译时,我在运行用于正确构建基于 .Net 2.0 的网站的 NAnt 脚本时遇到了一些问题。我最近将所有项目/解决方案文件升级到 VS2010,现在我的构建失败并出现以下错误:
[exec] C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Microsoft.Common.targets(2249,9): error MSB3086: Task could not find "sgen.exe" using the S dkToolsPath "" or the registry key "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v7.0A". Make sure the SdkToolsPath is set and the tool exists in the correct processor specific location under the SdkToolsPath and that the Microsoft Windows SDK is installed
[exec] C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Microsoft.Common.targets(2249,9): error MSB3086: Task could not find "sgen.exe" using the S dkToolsPath "" or the registry键“HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v7.0A”。确保设置了 SdkToolsPath 并且该工具存在于 SdkToolsPath 下正确的处理器特定位置,并且安装了 Microsoft Windows SDK
Now, I DO have prior versions (.Net 3.5) of the Windows SDK installed on the build server, and the full .Net 4.0 framework is installed, but I've not run across a .Net 4.0 specific version of the Windows SDK.
现在,我确实在构建服务器上安装了 Windows SDK 的先前版本 (.Net 3.5),并且安装了完整的 .Net 4.0 框架,但我没有遇到过 .Net 4.0 特定版本的 Windows SDK。
After a bit of experimentation and research, I finally just setup a new environmental variable "SDKToolsPath" and pointed it to the copy of sgen.exe in my windows 6.0 sdk folder. This generated the same error, but it got me to notice that even though the SDKToolsPath environmental variable IS set (confirmed that I can "echo" it at the command line and it has the expected value), the error message seems to indicated that it's not being read (note the empty quotes).
经过一些实验和研究,我终于设置了一个新的环境变量“SDKToolsPath”并将其指向我的 windows 6.0 sdk 文件夹中的 sgen.exe 副本。这产生了相同的错误,但它让我注意到,即使设置了 SDKToolsPath 环境变量(确认我可以在命令行“回显”它并且它具有预期值),错误消息似乎表明它是没有被阅读(注意空引号)。
Most of the information I've found is .Net 3.5 (or earlier) specific. Not much 4.0 related out there yet. Searching for error code MSB3086 generated nothing useful either. Any idea what this might be?
我发现的大部分信息都是特定于 .Net 3.5(或更早版本)的。还没有多少与 4.0 相关的内容。搜索错误代码 MSB3086 也没有产生任何有用的信息。知道这可能是什么吗?
Scott
斯科特
采纳答案by John Hann
I had to bite the bullet and install VS 2010 on our build server to fix this issue. As far as I can see, there's no 7.0A version of the Windows SDK available anywhere on MSDN. However, installing VS 2010 appears to install it, creating a 7.0A regkey and a 7.0A folder in Program Files\Microsoft SDKs\Windows.
我不得不硬着头皮在我们的构建服务器上安装 VS 2010 来解决这个问题。据我所知,MSDN 上没有任何可用的 Windows SDK 7.0A 版本。但是,安装 VS 2010 似乎会安装它,在 Program Files\Microsoft SDKs\Windows 中创建一个 7.0A regkey 和一个 7.0A 文件夹。
回答by Simmo
I couldn't face putting Visual Studio on the build server.
我无法面对将 Visual Studio 放在构建服务器上的问题。
The SDK v7.0A is the SDK installed with Visual Studio 2010 (The A indicates this is a VS release). Since then, a newer version has been released. Microsoft Windows SDK for Windows 7 and .NET Framework AKA v7.1.
SDK v7.0A 是与 Visual Studio 2010 一起安装的 SDK(A 表示这是一个 VS 版本)。从那时起,一个更新的版本已经发布。适用于Windows 7 和 .NET Framework AKA v7.1 的Microsoft Windows SDK 。
I've installed this on my build server. And then via the Windows SDK 7.1 Command Prompt (Start => All Programs => Microsoft Windows SDK 7.1), I set the default version of the SDK to be 7.1.
我已经在我的构建服务器上安装了它。然后通过 Windows SDK 7.1 命令提示符(开始 => 所有程序 => Microsoft Windows SDK 7.1),我将 SDK 的默认版本设置为 7.1。
Steps:
脚步:
cd Setup
WindowsSdkVer.exe -version:v7.1
Edit to include LordHits' comment:one doesn't need to install the entire SDK. Installing just the ".NET Development/Intellisense and Reference Assemblies" and ".NET Development/Tools" options is enough.
编辑以包含 LordHits 的评论:不需要安装整个 SDK。只安装“.NET Development/Intellisense and Reference Assemblies”和“.NET Development/Tools”选项就足够了。
回答by Daniel
Simply pass GenerateSerializationAssemblies parameter with value Off to your MsBuild.
只需将值为 Off 的 GenerateSerializationAssemblies 参数传递给您的 MsBuild。
msbuild.exe /p:GenerateSerializationAssemblies=Off
回答by Der_Meister
I manually pass the variables to MSBuild on build server.
我手动将变量传递给构建服务器上的 MSBuild。
msbuild.exe MyProject.csproj "/p:TargetFrameworkSDKToolsDirectory=C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6.1 Tools" "/p:AspnetMergePath=C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6.1 Tools"
回答by brandogs
I encountered a similar issue just recently on our build server.
我最近在我们的构建服务器上遇到了类似的问题。
I copied the 7.0A folder (C:\Program Files\Microsoft SDKs\Windows\7.0A) from my computer (which has VS2010 installed) on it to the build server in the same location.
我将 7.0A 文件夹 (C:\Program Files\Microsoft SDKs\Windows\7.0A) 从我的计算机(安装了 VS2010)复制到同一位置的构建服务器。
After create the following registry key: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v7.0A. Set InstallationFolder to C:\Program Files\Microsoft SDKs\Windows\7.0A.
创建以下注册表项后:HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v7.0A。将 InstallationFolder 设置为 C:\Program Files\Microsoft SDKs\Windows\7.0A。
You can also reference the registry on your machine with VS2010 already installed on it if you are confused about what to do with the registry on the build server.
如果您对如何处理构建服务器上的注册表感到困惑,您还可以在已安装 VS2010 的机器上引用注册表。
回答by John K
I've run into the same error but in a different situation: using VS 2010 Expressand trying to use Simmo's answerto explicitly set the SDK version - however WindowsSdkVer.exe (version setter tool) seems to not target Express (understandable since it's limited).
我遇到了同样的错误,但在不同的情况下:使用VS 2010 Express并尝试使用Simmo 的答案来明确设置 SDK 版本 - 但是 WindowsSdkVer.exe(版本设置工具)似乎没有针对 Express(可以理解,因为它是有限的)。
I'm using VS 2010 Express on Win 7 Prof. and it always wants to use v7.0A of the Win SDK (which does not have all the needed exes), and it deosn't matter which version I explicitly set as current using WindowsSdkVer.exe (It keeps reporting it set the current version of the SDK but for VS 2008 although though I only have 2010 Ex installed. )
我在 Win 7 Prof. 上使用 VS 2010 Express,它总是想使用 Win SDK 的 v7.0A(它没有所有需要的 exe),而且我明确设置为当前使用的版本并不重要WindowsSdkVer.exe(虽然我只安装了 2010 Ex,但它一直报告它设置了 SDK 的当前版本,但对于 VS 2008。)
So my cheap workaroundwas to install v7.0 WIN SDK (or another version like v7.1) and then rename its file system folder to v7.0A- basically I just lied to VS 2010 Express but it works now!
所以我的廉价解决方法是安装 v7.0 WIN SDK(或其他版本,如 v7.1),然后将其文件系统文件夹重命名为 v7.0A- 基本上我只是对 VS 2010 Express 撒谎,但它现在可以工作了!
回答by Maer007
One of your projects use sgen.exe (Server Generator) to generate web service. you need install SDKs to Build Server or remove Web Service references from the project.
您的项目之一使用 sgen.exe(服务器生成器)来生成 Web 服务。您需要安装 SDK 以构建服务器或从项目中删除 Web 服务引用。
回答by Steve
I suspect the targets file is overriding the tools path, I had a quick look in this file and is sets the SDKToolsPath to $TargetFrameworkSDKToolsDirectory under some of the targets in there. I don't think you should need to set these in the environment anyway, but they may need fixing in your project files.
我怀疑目标文件覆盖了工具路径,我快速查看了这个文件,并在其中的一些目标下将 SDKToolsPath 设置为 $TargetFrameworkSDKToolsDirectory。我认为您无论如何都不需要在环境中设置这些,但它们可能需要在您的项目文件中修复。
Note that according to this page http://nant.sourceforge.net/Nant does not support .Net 4.0, could this be the real problem?
请注意,根据此页面http://nant.sourceforge.net/Nant 不支持 .Net 4.0,这可能是真正的问题吗?
Sorry, I know this doesn't really answer your question:(
抱歉,我知道这并不能真正回答您的问题:(
回答by Robert Muehsig
I had the same issue on a brand new Windows 10 machine. My setup:
我在全新的 Windows 10 机器上遇到了同样的问题。我的设置:
- Windows 10
- Visual Studio 2015 Installed
- Windows 10 SDK
- 视窗 10
- 已安装 Visual Studio 2015
- 视窗 10 SDK
But I couldn't build .NET 4.0 projects:
但我无法构建 .NET 4.0 项目:
Die Aufgabe konnte "AL.exe" mit dem SdkToolsPath-Wert "" oder dem Registrierungsschlüssel "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v8.0A\WinSDK-NetFx40Tools-x86
Die Aufgabe konnte "AL.exe" mit dem SdkToolsPath-Wert "" 或 dem Registrierungsschlüssel "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v8.0A\WinSDK-NetFx40Tools-x86
Solution: After trying (and failing) to install the Windows 7 SDK (because thats also includes the .NET 4.0 SDK) I needed to install the Windows 8 SDK and make sure the ".NET Framework 4.5 SDK" is installed.
解决方案:在尝试(但失败)安装 Windows 7 SDK(因为这也包括 .NET 4.0 SDK)后,我需要安装 Windows 8 SDK 并确保安装了“.NET Framework 4.5 SDK”。
It's crazy... but worked.
这太疯狂了……但奏效了。
回答by Hans Passant
You don't actually have SDK version 7.0A installed? That's a problem you'll need to fix. Look in the VS2010 install log files to see what went wrong. The SDK should be present in c:\program files\microsoft sdks\windows\7.0a and the listed registry key must be present as well. Running with the 6.0a version of sgen.exe isn't okay, it is bound to use the wrong compiler.
您实际上没有安装 SDK 7.0A 版?这是你需要解决的问题。查看 VS2010 安装日志文件,看看出了什么问题。SDK 应存在于 c:\program files\microsoft sdks\windows\7.0a 中,并且列出的注册表项也必须存在。用6.0a版本的sgen.exe运行不行,肯定是用错了编译器。

