Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TFS won't compile string interpolation syntax

I updated to Visual Studio 2015 when it was released last week. Resharper suggested that I might like to update the following string using string.Format:

string filePath = HttpContext.Server.MapPath(string.Format("~/App_Data/{0}.xlsx", Guid.NewGuid()));

To use string interpolation:

string filePath = HttpContext.Server.MapPath($"~/App_Data/{Guid.NewGuid()}.xlsx");

I did this, and all is well.

However I've broken the build on TFS:

Controllers\MyController.cs (224): Unexpected character '$'

So it seems like the new features in C# 6 can't be compiled by our older, non-updated version of TFS.

The project is still targeted at using the Framework 4.5 however, I have not targeted 4.6. I (wrongly) assumed that still targeting the old framework would mean it could be built by other team members still using VS2013 along with our TFS build server.

So it looks like our TFS needs an update of... something.

What do I need to install on the TFS server to have it compile this new syntax? The latest version of the .NET Framework or something else?

like image 275
bgs264 Avatar asked Jul 30 '15 10:07

bgs264


Video Answer


2 Answers

Unfortunately, there doesn't appear to be an easy way to get older versions of TFS working with C# 6.0 without installing VS2015 on the TFS build server. If you can do that, I would suggest that. If, for whatever reason, you cannot, then the following worked for me:

I followed the instructions of the other answer, but that alone didn't work. I also had to edit the default TFS build process template (which in my case is found in $//BuildProcessTemplates) and change the ToolPath properties of the "Run MSBuild for Project" nodes to the location of MSBuild 14.0 (which usually is C:\Program Files (x86)\MSBuild\14.0\Bin).

You will then need to update your build definitions to use the new build template (if you had copy/edited a new one vs editing the original one).

At this point, you should be able to build C# 6 projects with TFS, but if you're trying to do web deployment/packaging as well, then there are still a few more steps.

On the build server, at C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0, there should be a Typescript folder and nothing else. On your local machine with VS2015, go to the same path. There should be a Web and WebApplications folder. Copy those over to the server's folder. You should now be able to package/deploy web projects as well.

like image 35
user3191350 Avatar answered Sep 20 '22 17:09

user3191350


Install .NET Framework 4.6 and Build Tools 2015 on your build server. Then override the ToolsVersion (/tv:14.0) in MSBuild arguments.

like image 188
KMoraz Avatar answered Sep 16 '22 17:09

KMoraz