19

I just recently began using the nameof() operator of C# 6.0 in my projects. Now (upon check-in, duh...) I (or better: the build agent) refused to build the project (which was compiling locally just fine) because it could not find the nameof() expression.

I began installing VS 2015 on the build controller as well as the TFS server itself, but to no avail. How can I get my TFS 2013 Update 5 to build projects with C# 6.0 features?

I already thought of editing the BuildProcessTemplate, but we're using the default template all the way through all our build definitions and I even didn't know if this was the right way to go.

2 Answers 2

21

You can either install the "Microsoft Build Tools 2015" on the build agent machine and configure the build template to use that version of msbuild, or else install the Microsoft.Net.Compilers NuGet package in the projects you want to build with the new compiler.

9
  • I want to stress this point. It is not enough to install multiple version of compilers side-by-side on the build agent machines, you must specify which one should be used by choosing the desired tool-chain. Commented Jul 24, 2015 at 7:42
  • 1
    Thank you. Care to elaborate on how to configure the build template for that?
    – SeToY
    Commented Jul 24, 2015 at 9:01
  • 1
    Hmm I would have thought installing TFS 2015 would have done the trick - but didn't. I get 'Invalid expression term' errors Commented Aug 27, 2015 at 20:49
  • 1
    @GiulioVian how would you go about pointing your build at the Microsoft.Net.Compilers from a nuget package?
    – Maslow
    Commented Sep 23, 2015 at 18:18
  • 4
    Installing the build tools is only the first step, you must also use a different build definition or modify the default. See stackoverflow.com/questions/32659106/…
    – Quango
    Commented Sep 28, 2015 at 9:00
1

I had the same issue with TFS 2015. My build definitions were in the XAML build definitions format - this format does not support C#6 features, even if you specify /p:VisualStudioVersion=14.0 or 15.0 for the MSBuild arguments in the advanced build process parameters.

Instead, use the new build format. In Visual Studio 2017 (yes, you can use VS 2017 with TFS 2015), it is available under section "Build definitions" (note that below that there is the old section "XAML Build definitions").

enter image description here

If you create a new build definition this way, a web site opens up where you have to create the build steps. The binary files appear under the "Artefacts" section. Unfortunately, I found no way to convert XAML build definitions to the new format, so you have to create it from scratch.

In the Visual Studio Build step, ensure that the field "Visual Studio Version" is set to "Latest".

Hint: To get the right files into your artifacts, you need to define Minimatch patterns. You can find the syntax here, in the example there you can find a copy file pattern for deploying a web project.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.