Running TFS Build with C# 6.0 features

2019-01-17 21:22发布

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条回答
劫难
2楼-- · 2019-01-17 21:46

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.

查看更多
祖国的老花朵
3楼-- · 2019-01-17 21:49

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.

查看更多
登录 后发表回答