我有一个在 VS2010 中开发的 C++ 项目(某种控制台 32 位应用程序),它在我的 PC(Windows 7 32 位)上构建得很好。我的电脑安装了 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"
.
网上关于如何处理这个问题的建议很少:
- 将部分注册表复制到下
HKLM\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v7.1
(HKCU
请参阅WindowsSdkDir is not set correct in Visual Studio 2008?)。我没有尝试这种解决方法,因为它看起来太丑了,并且构建过程将使用 SYSTEM-account 凭据运行。 WindowsSDKDir
作为额外参数传递给 MSBuild(如TeamCity 和 MSBuild Quirks #1中所建议的)。- 按照在TeamCity构建配置中包含搜索路径的答案
VCProjectEngine.dll.config.xml
中提出的调整(我没有在带有 Windows SDK 的 PC 上找到这样的文件)。 - 按照在 Visual Studio 2010 中未正确设置 WindowsSdkDir的答案中的建议更改项目属性中的平台工具集(我怀疑这会有所帮助,因为我的 PC 没有安装 Windows SDK 7.1)。
实际上,当编译CL.EXE
一切正常时(因为我已经定义INCLUDE
了LIB
变量),所以强制msbuild使用/传递环境变量将是一种解决方法......
有类似的问题:
- “在安装了 VS2010 的机器上和在安装了 7.1 SDK 的机器上构建之间的差异”,但对于 .NET 项目。
- 错误的 Windows SDK x64 编译警告(为 64 位平台构建 32 位项目)。
无论如何,有没有人在安装了 Windows SDK 的 PC 上成功构建 Visual C++ 2010 项目?