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.

Matt
  • 25,467
  • 18
  • 120
  • 187
SeToY
  • 5,777
  • 12
  • 54
  • 94

2 Answers2

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.

BozoJoe
  • 6,117
  • 4
  • 44
  • 66
Kevin Pilch
  • 11,485
  • 1
  • 39
  • 41
  • 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. – Giulio Vian Jul 24 '15 at 07:42
  • 1
    Thank you. Care to elaborate on how to configure the build template for that? – SeToY Jul 24 '15 at 09:01
  • 1
    Hmm I would have thought installing TFS 2015 would have done the trick - but didn't. I get 'Invalid expression term' errors – Simon_Weaver Aug 27 '15 at 20:49
  • 1
    @GiulioVian how would you go about pointing your build at the Microsoft.Net.Compilers from a nuget package? – Maslow Sep 23 '15 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 http://stackoverflow.com/questions/32659106/tfs-2013-building-net-4-6-c-sharp-6-0?rq=1 – Quango Sep 28 '15 at 09:00
  • I Cannot install MS Build Tools 2015 on Windows server 2008 R2. Any ideas ? – Charles Bretana Nov 05 '15 at 16:49
  • @Maslow you don't need to "point" anything, you just install the Nuget package. -- It modifies your msbuild files (`*.csproj`) for each project it's installed to, it will call the executable that it got from NuGet (the Roslyn compiler). – BrainSlugs83 Apr 04 '17 at 16:19
  • @GiulioVian how to choose which msbuild to choose in buil definition? – Beingnin Jul 12 '18 at 10:27
  • @NithinChandran this is too generic to reply in a comment: please submit a proper question describing your context (including versions for TFS, Visual studio on the agent, etc) – Giulio Vian Jul 12 '18 at 11:05
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.

Matt
  • 25,467
  • 18
  • 120
  • 187