在具有Windows SDK 7.1但没有VS2010的PC上构建C ++项目 [英] Building C++ project on a PC with Windows SDK 7.1 but without VS2010

查看:164
本文介绍了在具有Windows SDK 7.1但没有VS2010的PC上构建C ++项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个在VS2010中开发的C ++项目(某种形式的控制台32位应用程序),可以在我的PC(32位Windows 7)上很好地构建.我的电脑安装了Microsoft SDK 7.0A,我认为它与VS2010捆绑在一起.
我尝试在未安装任何Visual Studio的构建服务器上构建项目-那里仅存在Microsoft SDK 7.1.
我尝试在msbuild的帮助下构建项目(这最终将成为TeamCity的运行者的任务),并且在构建服务器上,我收到以下错误(提供了详细的日志):

I have a C++ project (some sort of a console 32-bit appplication) developed in VS2010, which builds just fine on my PC (Windows 7 32-bit). My PC has Microsoft SDK 7.0A installed, which I think comes bundled with VS2010.
I try to build the project on a build server, which doesn't have any Visual Studio installed - only Microsoft SDK 7.1 is present there.
I try to build the project with the help of msbuild (this will eventually become the task for TeamCity's runner), and on the build server I get following errors (the detailed log is provided):

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有关.

I suppose the issue is related to inability of msbuild to find Microsoft SDK, which is installed into "E:\Program Files\Microsoft SDKs\Windows\v7.1".

关于如何处理此问题的建议很少,可在网络上找到:

There are few advices how to handle this issue available on the Web:

  1. HKLM\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v7.1下的部分注册表复制到HKCU(请参阅 TeamCity和MSBuild Quirks#1 ).
  2. 根据 answer 中的建议将VCProjectEngine.dll.config.xml调整为答案中的建议,将项目属性中的平台工具集更改为
  1. Copy part of registry under HKLM\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v7.1 to HKCU (see WindowsSdkDir is not set correctly in Visual Studio 2008?). I didn't try this workaround because as it looks too ugly, and the build process will run with SYSTEM-account credentials.
  2. Pass WindowsSDKDir as an extra parameters to MSBuild (as proposed in TeamCity and MSBuild Quirks #1).
  3. Tweaking VCProjectEngine.dll.config.xml as proposed in the answer to Include Search Paths in TeamCity build Configurations (I haven't found such file on the PC with Windows SDK).
  4. Change the platform toolset in the project properties as proposed in the answer to WindowsSdkDir is not set correctly in Visual Studio 2010 (I doubt this will help, because my PC doesn't have Windows SDK 7.1 installed).

实际上,当使用CL.EXE进行编译时,一切都很好(因为我定义了INCLUDELIB变量),所以这是强制msbuild使用/传递环境变量的解决方法...

Actually when compiling with CL.EXE everything goes fine (because I have INCLUDE and LIB variables defined), so it would be a workaround to force msbuild to use/pass the environment variables...

有类似的问题:

  • "Differences between building on a machine with VS2010 installed and on a machine with the 7.1 SDK installed" but for .NET projects.
  • Erroneous Windows SDK x64 Compilation Warning (building 32-bit project for 64-bit platform).

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

推荐答案

我终于找到了一种可行且有意义的解决方法-在.
简而言之:在没有VS2010的PC上构建解决方案时,我必须明确指定Platform Toolset.该命令将如下所示:

I've finally found some kind of a workable and meaningful workaround for the issue - inside "Can we build *.vcxproj(c++ project) using MSBuild 4.0 without installing the Visual Studio 2010?".
In short: I have to explicitly specify the Platform Toolset when building the solution on a PC without VS2010. The command will look like:

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

如果您的项目已将v100v90指定为平台工具集,则可能需要采取相同的方法.

You will probably need to go same way if your project has v100 or v90 specified as the Platform Toolset.

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

And an extra hint for TeamCity's enthusiasts, running the server on a PC with a lone Windows SDK installed.
Instead of modifying all build steps, it is enough to specify the Platform Toolset in the agent's properties. To do that add following line to ?:\TeamCity\buildAgent\conf\buildAgent.properties:

system.PlatformToolset=Windows7.1SDK

建设愉快! :)

这篇关于在具有Windows SDK 7.1但没有VS2010的PC上构建C ++项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆