VCTargetsPath is wrong when building with MSBuild on build server

34,096

Solution 1

In my case, my build definition was configured to build my .sln file instead of my .proj file. I remember configuring it to build the MSBuild project, but somehow it seems to have reverted to the Solution.

Anyway, I found two solutions to the problem:

  1. Make sure to build the .proj file (where the tools version is indeed set to 12.0).
  2. Explicitly set the VCTargetsPath.

Solution 2

Try to set up environment variable

VisualStudioVersion=12.0

or pass it explicitly as property to msbuild on commandline

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

I think it is because Microsoft tries to keep compatibility with older Visual Studios.

see Visual Studio project compatibility and VisualStudioVersion

Share:
34,096
l33t
Author by

l33t

Updated on June 08, 2020

Comments

  • l33t
    l33t almost 4 years

    In my C++ project, Test.wcxproj, I have the following configurations defined:

    <?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>
    

    Then I have the problematic import of the default C++ properties:

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

    When my build server builds my MSBuild project file (configuration is Release and platform is Any CPU), I get this error:

    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.
    

    The relevant parts of my MSBuild project file look like this:

    <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>
    

    The problem

    In my MSBuild project file, I am using ToolsVersion="12.0". Visual Studio 2013 is indeed installed, so I don't understand why it chooses to use v4.0\v110. Are my project configurations for some reason skipped by MSBuild? I guess I could somehow override this folder using the /p switch, but I want my .proj file to be self-contained.

  • Volker von Einem
    Volker von Einem about 10 years
    Thanks a lot - I was building an upgraded sln containing a vcxproj file via msbuild - this was constantly giving error below - now it works! 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') cannot be found. To build using the v120 build tools, either click the Project menu or right-click the solution, and thenselect "Update VC++ Projects...". Install v120 to build using the v120 build tools. [D:\Projekt...
  • Lukas Liesis
    Lukas Liesis almost 6 years
    i needed to update env and Explicitly set the VCTargetsPath