为什么Visual Studio 2013使用错误的SdkToolsPath for lc.exe?

为什么Visual Studio 2013使用错误的SdkToolsPath for lc.exe?

问题描述:

我正在将Visual Studio 2013与asp.net项目一起使用.其中一个项目给出以下错误. 为什么在错误的路径中寻找LC.exe?我的Windows 8.1 SDK已安装,并且在

I am using Visual Studio 2013 with an asp.net project. One of the projects gives the error below. Why is it looking for LC.exe in the wrong path? My Windows 8.1 SDK is installed and I have an lc.exe at

C:\Program Files (x86)\Microsoft SDKs\Windows\v8.1A\bin\NETFX 4.5.1 Tools

和64位版本,我在

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v8.1A

我正在查看C:\Windows\Microsoft.NET\Framework\v4.0.30319下的Microsoft.Common.targets,并且此密钥存在:SdkToolsPath="$(TargetFrameworkSDKToolsDirectory)".然后查看

I am looking at Microsoft.Common.targets under C:\Windows\Microsoft.NET\Framework\v4.0.30319 and this key exists: SdkToolsPath="$(TargetFrameworkSDKToolsDirectory)". Then looked at Microsoft.NetFramework.CurrentVersion.props under

C:\Program Files (x86)\MSBuild\12.0\Bin

TargetFrameworkSDKToolsDirectory$SDK40ToolsPath中定义.根据MSBuild /v:diag

SDK40ToolsPath = C:\Program Files (x86)\Microsoft SDKs\Windows\v8.1A\bin\NETFX 4.5.1 Tools 

看起来不错. .NET 4.0中VS中的项目目标.

which looks good. The project's target in VS in .NET 4.0.

那么为什么它仍然查看错误的文件夹或注册表项?有趣的是,当我收到错误消息后重建项目时,项目可以正常构建.

So why is it still looking at the wrong folder or registry key? The interesting thing is when I rebuild the project after getting the error message, the project builds fine.

Error   5   
Task could not find "LC.exe" using the SdkToolsPath 
    "C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\bin\NETFX 4.0 Tools\" 
or the registry key 
    "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v8.0A\WinSDK-NetFx40Tools-x86".
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   
    C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets  2428    5   SuperReports

事实证明,您可以直接在.csproj文件中指定SDK的路径:

It turns out you can specify the path to the SDK directly in the .csproj file:

<TargetFrameworkSDKToolsDirectory>C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6 Tools</TargetFrameworkSDKToolsDirectory>

,然后该版本以这种方式找到了lc.exe.

and the build found lc.exe that way.

我以前曾期望使用<SdkToolsPath>进行设置,但这没有用.在Microsoft.Common.targets中,从TargetFrameworkSDKToolsDirectory设置了SdkToolsPath,所以我尝试了一下并成功了.这是在Visual Studio 2015上,并且从ant调用了msbuild.

I previously expected to set this using <SdkToolsPath>, but that didn't work. In Microsoft.Common.targets, SdkToolsPath gets set from TargetFrameworkSDKToolsDirectory, so I tried that and it worked. This is on Visual Studio 2015, and msbuild being called from ant.

通过找到的解决方案使用不正确版本的sgen.exe来生成XmlSerializer dll的MSBuild?