简体   繁体   中英

CS1705 error while adding a C++ project to solution

Hi and thanks in advance. I'm using TFS build 2013 (team services, not on premise) to build my solution. After creating a new C++ project in the solution I'm unable to build successfully. The error I'm getting on the build machine is:

    C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\CodeAnalysis\Microsoft.CodeAnalysis.targets
    (219): An error has occurred during compilation. error CS1705: Assembly 'Microsoft.Build.Utilities.Core,
    Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' uses 'Microsoft.Build.Framework,
    Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' which has a higher
    version than referenced assembly 'Microsoft.Build.Framework, Version=12.0.0.0, Culture=neutral,
    PublicKeyToken=b03f5f7f11d50a3a'

    C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\CodeAnalysis\Microsoft.CodeAnalysis.targets
    (219): The "SetEnvironmentVariable" task was not found. Check the following: 1.) The name of the task in the project file is the same as the name
    of the task class. 2.) The task class is "public" and implements the Microsoft.Build.Framework.ITask
    interface. 3.) The task is correctly declared with <UsingTask> in the project file, or
    in the *.tasks files located in the "C:\Program Files (x86)\MSBuild\14.0\bin\amd64" directory.

I've red about error CS1705 on the internet but I still don't understand why I get this error - the project is an empty project which has no references what so ever and no other project reference it either.

I'm targeting .NET framework 4.6.1 on all my C# projects and in my build definition I'm adding these msbuild arguments: /tv:14.0 /p:VisualStudioVersion=14.0 hence it uses the 2015's version of the c# compiler. The target platform for this C++ project is VS 2015 (v140) as follows: C++ project configuration

Needless to say that when I'm removing this project from the list of project to build (configuration manager) - the solution builds successfully.

Any help/clue would be greatly appreciated!

The problem was something other than what I thought it was. Seems it's got something to do with CodeAnalysis and some environment variable related to it. In my build definition I'm disabling CodeAnalysis and even inside the C++ project properties It's explicitly disabled. After I commented out some attributes on the "SetCABuildNativeEnvironmentVariables" target inside this file on the build machine:

"C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\CodeAnalysis\Microsoft.CodeAnalysis.targets"

The problem disappered.

This is a nasty workaround however since I'm not fully aware of what's really happening.

Thanks a lot anyways!

Seems there are something still point to "Microsoft.Build.Framework, Version=12.0.0.0"

The /tv:14.0 command argument doesn't work as expected. See: BuildActivity ignores ToolsVersion

As a workaround, you need to customize the build process template:

  1. Open the template in Visual Studio and find the Run MSBuild for Project MSBuild activity.
  2. Set ToolVersion to "14.0".
  3. Set ToolPath to target to MSBuild14 (by default: "C:\\Program Files (x86)\\MSBuild\\14.0\\Bin").
  4. Check in this build process template and re-queue the build.

You can also refer the answer from Marson in TFS 2013 building .NET 4.6 / C# 6.0

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM