【问题标题】:VCTargetsPath is wrong when building with MSBuild on build server在构建服务器上使用 MSBuild 构建时 VCTargetsPath 错误
【发布时间】:2013-12-03 06:52:33
【问题描述】:

在我的 C++ 项目 Test.wcxproj 中,我定义了以下配置:

<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="12.0"
    xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
    <ProjectConfiguration Include="Debug|Win32">
      <Configuration>Debug</Configuration>
      <Platform>Win32</Platform>
    </ProjectConfiguration>
    <ProjectConfiguration Include="Debug|x64">
      <Configuration>Debug</Configuration>
      <Platform>x64</Platform>
    </ProjectConfiguration>
    <ProjectConfiguration Include="Release|Win32">
      <Configuration>Release</Configuration>
      <Platform>Win32</Platform>
    </ProjectConfiguration>
    <ProjectConfiguration Include="Release|x64">
      <Configuration>Release</Configuration>
      <Platform>x64</Platform>
    </ProjectConfiguration>
  </ItemGroup>

然后我有默认 C++ 属性的 problematic 导入:

<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />

当我的构建服务器构建我的 MSBuild 项目文件时(配置为 Release,平台为 Any CPU),我收到此错误:

error MSB4019: The imported project "C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V110\Microsoft.Cpp.Default.props" was not found. Confirm that the path in the <Import> declaration is correct, and that the file exists on disk.

我的MSBuild 项目文件的相关部分如下所示:

<ItemGroup>
   <ProjectFiles Include="$(MSBuildProjectDirectory)\**\*.csproj" />
   <ProjectFiles Include="$(MSBuildProjectDirectory)\**\*.vcxproj" />
</ItemGroup>
<PropertyGroup>
    <Configuration>Release</Configuration>
    <Platform>x64</Platform>
    <OutputFolder>$(MSBuildProjectDirectory)\BuildOutput\$(Configuration)</OutputFolder>
    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">$(MSBuildProjectDirectory)</SolutionDir>
</PropertyGroup>
...
<Target Name="Compile">
    <MSBuild Projects="@(ProjectFiles)" Targets="Build" Properties="Configuration=$(Configuration);Platform=$(Platform);OutputPath=$(OutputFolder)\$(MSBuildProjectName);SolutionDir=$(SolutionDir)\" />
</Target>

问题

在我的MSBuild 项目文件中,我使用的是ToolsVersion="12.0"。确实安装了Visual Studio 2013,所以我不明白为什么它选择使用v4.0\v110。我的项目配置是否因某种原因被MSBuild 跳过?我想我可以使用/p 开关以某种方式覆盖此文件夹,但我希望我的.proj 文件是独立的。

【问题讨论】:

  • 能否请您提供该项目的PlatformToolset属性?看起来您在未安装 vc2012 的构建机器上构建 vc2012 项目,或者您从命令行显式传递 PlatformToolset 属性。 v110 是 vc2012 平台工具集。 v120 是 vc2013 默认平台工具集。
  • 我们使用VS2013升级了一个vc2010项目。现在它在项目文件中到处都是“v120”。我们没有从命令行指定 PlatformToolset。我开始怀疑构建机器还剩下一些 VC11 beta 片段。
  • 嘿,我也有同样的问题。曾经解决过吗? :)

标签: tfs msbuild visual-studio-2013


【解决方案1】:

尝试设置环境变量

VisualStudioVersion=12.0

或在命令行上将其作为属性显式传递给 msbuild

msbuild.exe <project or solution to build> /p:VisualStudioVersion=12.0

我认为这是因为微软试图保持与旧版 Visual Studio 的兼容性。

Visual Studio project compatibility and VisualStudioVersion

【讨论】:

  • 非常感谢 - 我正在通过 msbuild 构建一个包含 vcxproj 文件的升级 sln - 这经常在下面给出错误 - 现在它可以工作了! C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V110\Microsoft.Cpp.Platform.targets(44,5): error MSB8020: The builds tools for v120 (Platform Toolset = 'v120')找不到。要使用 v120 构建工具进行构建,请单击“项目”菜单或右键单击解决方案,然后选择“更新 VC++ 项目...”。安装 v120 以使用 v120 构建工具进行构建。 [D:\项目...
【解决方案2】:

在我的例子中,我的构建定义被配置为构建我的.sln 文件而不是我的.proj 文件。我记得配置它来构建 MSBuild 项目,但不知何故它似乎已经恢复到解决方案。

不管怎样,我找到了两个解决问题的方法:

  1. 确保构建.proj 文件(其中工具版本确实设置为12.0)。
  2. 显式设置VCTargetsPath

【讨论】:

  • 我需要更新环境和Explicitly set the VCTargetsPath