在没有安装VS2010的Windows SDK 7.1 PC上构建C ++项目

10

我有一个C++项目(一种控制台32位应用程序),在我的PC上(Windows 7 32位)上构建得很好。我的PC安装了Microsoft SDK 7.0A,我认为这是与VS2010捆绑在一起的。
我尝试在没有安装任何Visual Studio的构建服务器上构建该项目 - 只有Microsoft SDK 7.1存在。
我尝试使用msbuild构建项目(最终将成为TeamCity运行程序的任务),并在构建服务器上获得以下错误(提供详细日志):

Project "E:\win\core.sln" on node 1 (default targets).
ValidateSolutionConfiguration:
  Building solution configuration "Debug|Win32".
Project "E:\win\core.sln" (1) is building "E:\win\core_unittests.vcxproj" (2) on node 1 (default targets).
Project "E:\win\core_unittests.vcxproj" (2) is building "E:\cpptest\win\cpptest.vcxproj" (3) on node 1 (default targets).
C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.Targets(847,9): warning MSB3644: The reference assemblies for framework ".NETFramework,Version=v4.0" were not found. To resolve this, install the SDK or Targeting Pack for this framework version or retarget your application to a version of the framework for which you have the SDK or Targeting Pack installed. Note that assemblies will be resolved from the Global Assembly Cache (GAC) and will be used in place of reference assemblies. Therefore your assembly may not be correctly targeted for the framework you intend. [E:\cpptest\win\cpptest.vcxproj]
C:\Program Files\MSBuild\Microsoft.Cpp\v4.0\Microsoft.CppBuild.targets(297,5): warning MSB8003: Could not find WindowsSDKDir variable from the registry.  TargetFrameworkVersion or PlatformToolset may be set to an invalid version number. [E:\win\cpptest.vcxproj]
InitializeBuildStatus:
  Touching "E:\cpptest\win\..\..\..\out\Debug\cpptest\cpptest.unsuccessfulbuild".
ClCompile:
  C:\Program Files\Microsoft Visual Studio 10.0\VC\bin\CL.exe /c /ZI /nologo /W3 /WX- /Od /Oy- /D WIN32 /D _DEBUG /D _LIB /D _UNICODE /D UNICODE /Gm /EHsc /RTC1 /MTd /GS /fp:precise /Zc:wchar_t /Zc:forScope /Fo"E:\cpptest\win\..\..\..\out\Debug\cpptest\\" /Fd"E:\cpptest\win\..\..\..\out\Debug\cpptest\vc100.pdb" /Gd /TP /analyze- /errorReport:queue ../missing.cpp
  missing.cpp
e:\cpptest\missing.cpp(36): fatal error C1083: Cannot open include file: 'windows.h': No such file or directory [E:\cpptest\win\cpptest.vcxproj]

我想问题与msbuild无法找到已安装在"E:\Program Files\Microsoft SDKs\Windows\v7.1"的Microsoft SDK有关。网上有一些处理此问题的建议:
  1. 将注册表的一部分从HKLM\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v7.1复制到HKCU(请参见WindowsSdkDir is not set correctly in Visual Studio 2008?)。我没有尝试此解决方法,因为它看起来太丑陋,并且构建过程将使用SYSTEM账户凭据运行。
  2. WindowsSDKDir作为额外参数传递给MSBuild(如TeamCity and MSBuild Quirks #1中所提出的)。
  3. 按照Include Search Paths in TeamCity build Configurations中的answer所提出的方法调整VCProjectEngine.dll.config.xml(在装有Windows SDK的PC上未找到此文件)。
  4. 按照WindowsSdkDir is not set correctly in Visual Studio 2010中的answer所提出的方法更改项目属性中的平台工具集(我怀疑这并不能帮助解决问题,因为我的PC没有安装Windows SDK 7.1)。
实际上,使用CL.EXE编译一切都很顺利(因为我定义了INCLUDELIB变量),所以强制msbuild使用/传递环境变量将是一种解决方法...
存在类似的问题: 无论如何,有没有人成功地在安装了Windows SDK的PC上构建Visual C++ 2010项目
2个回答

12

我终于找到了一个可行且有意义的解决方法 - 在“在不安装Visual Studio 2010的情况下,我们是否可以使用MSBuild 4.0构建*.vcxproj(C ++项目)?”中。
简而言之:当在没有VS2010的电脑上构建解决方案时,我必须显式指定平台工具集。命令如下:

msbuild /p:PlatformToolset=Windows7.1SDK core.sln

如果你的项目指定了v100v90作为平台工具集,那么你可能需要走同样的路线。

对于TeamCity的爱好者,这里有一个额外的提示:如果在安装了独立Windows SDK的PC上运行服务器,那么可以在代理的属性中指定平台工具集,而无需修改所有构建步骤。 要做到这一点,请将以下行添加到?:\TeamCity\buildAgent\conf\buildAgent.properties文件中:

system.PlatformToolset=Windows7.1SDK

祝您建设愉快! :)


你好,能否更明确地说明如何在带有teamcity代理的构建服务器上运行Visual Studio 2010 C++项目?使用Visual Studio 2010解决方案构建步骤不起作用,因为似乎MSBuild依赖于缺失的mspdb100.dll DLL。 - Stefano
@Stefano,通常情况下,在您的情况下正确的解决方案是将 mspdb100.dll 的目录添加到 %PATH% 中。 - AntonK

1

另外,您可以将此节点和值添加到注册表中(根据您的安装目录和Win 32/64版本进行正确设置)。

---开始.reg文件---

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\VisualStudio\10.0\Setup\VS]
"ProductDir"="C:\\Program Files (x86)\\Microsoft Visual Studio 10.0\\"

---结束 .reg 文件---

由于 MSBuild 脚本 %ProgramFiles(x86)%\MSBuild\Microsoft.Cpp\v4.0\Platforms\Win32\PlatformToolsets\Windows7.1SDK\Microsoft.Cpp.Win32.Windows7.1SDK.props" 搜索 VSInstallDir。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接