MSBuild with C# 6 and UpgradeTemplate.xaml

If you use UpgradeTemplate for your MSBuild, getting it to work with C# 6 can be a little tricky.
First, we need to set the tools version by passing these parameters to MSBuild:
/tv:14.0 /p:VisualStudioVersion=14.0

This, however, may not change the MSBuild version used to run your build. TFS Build server may still use the MSBuild from your .Net framework folder (C:\Windows\Microsoft.NET\Framework64\v4.0.30319). To verify the location of your MSBuild, used by the TFS, open one of your completed builds, and check the Diagnostics tab. It should show the MSBuild.exe forlder in the “Run TfsBuild for Configuration Folder” step.

To fix this, we need to explicitly set the ToolPath for the MSBuild template.
Open the UpgradeTemplate.xaml in Visual Studio
Right click on “Run TfsBuild for Configuration” -> Properties
Set the ToolPath property to point to your msbuild: “C:\Program Files (x86)\MSBuild\14.0\Bin\”
Don’t forget the quotation marks.

While you’re at it, check out Target Framework Migrator – it’s a Visual Studio extension, which helps update all of your projects to target a specific .Net version. Can be quite helpful when you have a lot of projects.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.