Running TFS Build with C# 6.0 features

11,576

Solution 1

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.

Solution 2

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.

Share:
11,576
SeToY
Author by

SeToY

Loves: WPF, SharePoint, LINQ Hates: WPF, SharePoint, LINQ Beauty is more important in computing than anywhere else in technology because software is so complicated. Beauty is the ultimate defence against complexity. - David Gelernter Hilarious. Even as a .NET developer.

Updated on June 06, 2022

Comments

  • SeToY
    SeToY almost 2 years

    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.

  • Giulio Vian
    Giulio Vian almost 9 years
    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.
  • SeToY
    SeToY almost 9 years
    Thank you. Care to elaborate on how to configure the build template for that?
  • aruno
    aruno over 8 years
    Hmm I would have thought installing TFS 2015 would have done the trick - but didn't. I get 'Invalid expression term' errors
  • Nicolas Fall
    Nicolas Fall over 8 years
    @GiulioVian how would you go about pointing your build at the Microsoft.Net.Compilers from a nuget package?
  • Quango
    Quango over 8 years
    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/…
  • Charles Bretana
    Charles Bretana over 8 years
    I Cannot install MS Build Tools 2015 on Windows server 2008 R2. Any ideas ?
  • BrainSlugs83
    BrainSlugs83 about 7 years
    @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).
  • Beingnin
    Beingnin almost 6 years
    @GiulioVian how to choose which msbuild to choose in buil definition?
  • Giulio Vian
    Giulio Vian almost 6 years
    @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)