22

How can I build a Visual Studio 2015 solution using C# 6.0 Features at a TFS 2012 without installing Visual Studio 2015 on a build agent (using Microsoft Build Tools 2015 RC)

I Already installed MSBuild Tools but I still get exceptions. How can I Tell my build template to use MSBuild 14 (Only for one project)

And why does my TFS 2012 compile async and await (c# 5.0) without any problems while the BuildAgent only has Visual Studio 2012 installed?

I tried changing the ToolPath of my BuildProcessTemplate to MSBuild/14.0/ but I get a build error:

C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Microsoft.CSharp.targets (316): "csc2.exe" exited with code -532462766.

Installing the Microsoft.Net.Compilers 1.0.0-rc2 Compilers gives the same error.

If I compile the project using the command line I get the exact same error / although there is no error on my dev machine when using the command line with the exact same arguments.

This is the Exception I get in the command line:

C:\Program Files (x86)\MSBuild\14.0\bin\csc2.exe /noconfig /nowarn:1701,1702 /nostdlib+ /errorreport:prompt /warn:4 /define:TRACE /highentro.....
     Unhandled Exception: System.InvalidProgramException: Common Language Runtime detected an invalid program.
        at System.Collections.Immutable.SecurePooledObject`1.Use[TCaller](TCaller& caller)
        at System.Collections.Immutable.SortedInt32KeyNode`1.Enumerator.PushLeft(SortedInt32KeyNode`1 node)
        at System.Collections.Immutable.SortedInt32KeyNode`1.Enumerator..ctor(SortedInt32KeyNode`1 root)
        at System.Collections.Immutable.ImmutableDictionary`2.Enumerator..ctor(SortedInt32KeyNode`1 root, Builder builder)
        at Microsoft.CodeAnalysis.RuleSet.GetDiagnosticOptionsFromRulesetFile(Dictionary`2 diagnosticOptions, String resolvedPath, IList`1 diagnosticsOpt, CommonMessageProvider messageProviderOpt)
        at Microsoft.CodeAnalysis.CSharp.CSharpCommandLineParser.Parse(IEnumerable`1 args, String baseDirectory, String additionalReferencePaths)
        at Microsoft.CodeAnalysis.CSharp.CSharpCommandLineParser.CommonParse(IEnumerable`1 args, String baseDirectory, String additionalReferencePaths)
        at Microsoft.CodeAnalysis.CommonCompiler..ctor(CommandLineParser parser, String responseFile, String[] args, String baseDirectory, String additionalReferencePaths)
        at Microsoft.CodeAnalysis.CSharp.CSharpCompiler..ctor(CSharpCommandLineParser parser, String responseFile, String[] args, String baseDirectory, String additionalReferencePaths)
        at Microsoft.CodeAnalysis.CSharp.CommandLine.Csc..ctor(String responseFile, String baseDirectory, String[] args)
        at Microsoft.CodeAnalysis.CSharp.CommandLine.Csc.Run(String[] args)
        at Microsoft.CodeAnalysis.BuildTasks.BuildClient.RunWithConsoleOutput(String[] args, RequestLanguage language, Func`2 fallbackCompiler)
        at Microsoft.CodeAnalysis.CSharp.CommandLine.Program.Main(String[] args)
        at Microsoft.CodeAnalysis.CSharp.CommandLine.Csc2.Main(String[] args)
MatthewMartin
  • 29,993
  • 30
  • 102
  • 160
quadroid
  • 7,621
  • 5
  • 41
  • 71

4 Answers4

17

I used TFS2013 U5, but it will be same:

  • installed VS2015 RTM on BuildServer machine
  • put this into MSBuild arguments in Process part of BuildTemplate

/tv:14.0 /p:GenerateBuildInfoConfigFile=false /p:VisualStudioVersion=14.0

Both compiling and VS-unit tests are now running OK.

Jiří Zídek
  • 354
  • 2
  • 6
5

Try using either

/p:VisualStudioVersion=14.0

or

/tv:14 

In your build arguments

qJake
  • 15,642
  • 13
  • 73
  • 125
fenix2222
  • 4,323
  • 3
  • 31
  • 54
  • This won't work alone - you need to change the build definition used. See http://stackoverflow.com/questions/32659106/tfs-2013-building-net-4-6-c-sharp-6-0?rq=1 – Quango Sep 28 '15 at 09:03
  • It worked fine for me. After adding this build argument, build started working – fenix2222 Sep 28 '15 at 11:54
2

The answer by Jiří Zídek is correct but it was missing one crucial detail. I had to do the following to get things working on TFS 2012 Update 2:

  1. install Visual Studio 2015 on the build server
  2. set the MSBuild Arguments in the build definition to /p:VisualStudioVersion=14.0 (i.e. Visual Studio 2015 mode)
  3. in each project that uses C# 6 syntax, install the NuGet package Microsoft.Net.Compilers install-package Microsoft.Net.Compilers

It was #3 that made the difference for me.

John Reilly
  • 4,594
  • 4
  • 32
  • 52
  • Note that Microsoft.Net.Compilers is to allow Roslyn support when you don't have the latest toolset. So you haven't fixed your issue you've done a workaround meant for older versions of Visual Studio. – Lex Feb 01 '16 at 19:08
  • I'm not sure I understand Lex? For my own case I'm just trying to work around older versions of TFS; not older versions of Visual Studio. If there's something that's missing please do highlight it; but as far as I can tell my own issue is fixed. – John Reilly Feb 03 '16 at 13:41
  • If you are using the VS2015 Toolset (14.0) you shouldn't need that package. Also you may still run into problems with some tooling (such at MSTest). We worked round this on a TFS 2013 Application server by installing the TFS 2015 Agent software (it is backwards compatible). – Lex Feb 22 '16 at 16:22
  • Even though VS2015 is installed on the TFS2012 build agent passing /p:VisualStudioVersion=14.0 alone did not work. The Microsoft.Net.Compilers package installation was still necessary. Maybe there's a key difference between TFS2012 and TFS2013. – John Reilly Mar 05 '16 at 06:16
0

For those of you using TFS 2012 and VS 2017 bypassing 2015, you can follow my answer on enter link description here

TFS 2012 and VS 2017 continuous integration build

gavin
  • 1,167
  • 1
  • 10
  • 16