【问题标题】:Building C++ project on a PC with Windows SDK 7.1 but without VS2010在具有 Windows SDK 7.1 但没有 VS2010 的 PC 上构建 C++ 项目
【发布时间】:2012-01-28 00:39:55
【问题描述】:

我有一个在 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" 中的 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. 按照answer 中的建议将VCProjectEngine.dll.config.xml 调整为Include Search Paths in TeamCity build Configurations(我在装有Windows SDK 的PC 上没有找到这样的文件)。
  4. 按照the answer 中的建议将项目属性中的平台工具集更改为WindowsSdkDir is not set correctly in Visual Studio 2010(我怀疑这会有所帮助,因为我的PC 没有安装Windows SDK 7.1)。

实际上当使用CL.EXE 编译时一切正常(因为我定义了INCLUDELIB 变量),因此强制msbuild 使用/传递环境变量将是一种解决方法...

也有类似的问题:

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

【问题讨论】:

    标签: visual-studio-2010 visual-c++ winapi msbuild-4.0


    【解决方案1】:

    我终于在"Can we build *.vcxproj(c++ project) using MSBuild 4.0 without installing the Visual Studio 2010?" 内部找到了某种可行且有意义的解决方法。
    简而言之:在没有 VS2010 的 PC 上构建解决方案时,我必须明确指定平台工具集。该命令将如下所示:

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

    如果您的项目将v100v90 指定为平台工具集,您可能需要采用相同的方式。

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

    system.PlatformToolset=Windows7.1SDK
    

    建设愉快! :)

    【讨论】:

    • 嗨,您能否更好地指定如何在具有团队城市代理的构建服务器上运行 Visual Studio 2010 C++ 项目?使用 Visual Studio 2010 解决方案构建步骤不起作用,因为 MSBuild 似乎依赖于缺少的 mspdb100.dll DLL
    • @Stefano,通常情况下正确的解决方案是将mspdb100.dll 的目录添加到%PATH%
    【解决方案2】:

    您还可以将此节点和值添加到注册表(与您的安装目录和 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。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-10-24
      • 2011-03-03
      • 2011-05-04
      • 1970-01-01
      • 1970-01-01
      • 2012-01-22
      相关资源
      最近更新 更多