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

Ant*_*onK 10 winapi visual-studio-2010 visual-c++ msbuild-4.0

我有一个在VS2010中开发的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]
Run Code Online (Sandbox Code Playgroud)

我想这个问题与msbuild无法找到安装的Microsoft SDK有关"E:\Program Files\Microsoft SDKs\Windows\v7.1".

关于如何在Web上处理此问题的建议很少:

  1. 将部分注册表复制HKLM\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v7.1HKCU(请参阅Visual Studio 2008中未正确设置WindowsSdkDir?).我没有尝试这种解决方法,因为它看起来太丑了,构建过程将使用SYSTEM帐户凭据运行.
  2. 通过WindowsSDKDir作为一个额外的参数的MSBuild(如中提出的TeamCity和怪癖的MSBuild#1).
  3. 调整VCProjectEngine.dll.config.xml中所提出的答案的包含搜索路径中的TeamCity构建配置(我还没有发现与Windows SDK在PC上这样的文件).
  4. 改变平台工具集在项目属性中提出的答案WindowsSdkDir没有在Visual Studio 2010中设置正确(我怀疑这会有所帮助,因为安装了Windows SDK 7.1我的电脑不具备).

实际上编译时CL.EXE一切顺利(因为我INCLUDELIB变量定义的),所以这将是一个变通方法来强制的MSBuild使用/通过环境变量...

有类似的问题:

无论如何,有没有人成功在安装了Windows SDK的PC上构建Visual C++ 2010项目

Ant*_*onK 11

我终于找到了一些可行且有意义的解决方法 - 在"我们可以使用MSBuild 4.0构建*.vcxproj(c ++项目)而不安装Visual Studio 2010吗?" .
简而言之:在没有VS2010的PC上构建解决方案时,我必须明确指定平台工具集.该命令将如下所示:

msbuild /p:PlatformToolset=Windows7.1SDK core.sln
Run Code Online (Sandbox Code Playgroud)

如果您的项目已经v100v90指定为Platform Toolset,您可能需要采用相同的方式.

还为TeamCity的爱好者提供了额外的提示,在安装了单独Windows SDK的PC上运行服务器.
不必修改所有构建步骤,只需在代理的属性中指定Platform Toolset即可.为此,请将以下行添加到?:\TeamCity\buildAgent\conf\buildAgent.properties:

system.PlatformToolset=Windows7.1SDK
Run Code Online (Sandbox Code Playgroud)

快乐的建筑!:)