35

We use TFS 2013 to as our build server. I've started a C# 6.0 project and I am trying to get it to build. I am using the new null-conditional operators, and my build chokes. I've tried installing several things on the TFS server, including the targeting pack and VS 2015. I've tried providing /tv:14.0 to the MSBuild arguments.

Configuration\EntityEntityConfig.cs (270): Invalid expression term '.'
Configuration\EntityEntityConfig.cs (283): Invalid expression term '.'
Configuration\EntityEntityConfig.cs (283): Syntax error, ':' expected
... etc.

At this point, I have no idea what else to try. Any suggestions would be greatly appreciated.

Wesley Lomax
  • 2,067
  • 2
  • 20
  • 34
zimdanen
  • 5,508
  • 7
  • 44
  • 89
  • If you run that C#6.0 project directly in VS on the build agent machine, will you get the same error message? – Vicky - MSFT Sep 21 '15 at 09:33
  • @Vicky: Builds fine in VS on the build agent machine. Runs as well (though runs into auth issues because I didn't want to mess around with IIS too much). Trying your solution below. – zimdanen Sep 21 '15 at 15:55
  • 2
    [This thread](http://stackoverflow.com/questions/28287737/c-sharp-6-0-tfs-builds) is quite similar, and proposes a different idea to reference Microsoft.Net.Compilers nuget package. Have you tried that? – Yan Sklyarenko Sep 25 '15 at 13:19
  • @YanSklyarenko: I tried everything in that thread other than adding that package, and I'm a little leery of doing that, but I will try it and report back. – zimdanen Sep 25 '15 at 15:26
  • @YanSklyarenko: That worked! It's not perfect, since it involves project changes that we'll have to back out once we move over to TFS 2015, but it at least lets me use the build server. Add as answer? I'll wait in awarding in case someone is able to find a way to get this to work without the project changes. – zimdanen Sep 25 '15 at 16:33
  • @zimdanen, well, although it sounds very appealing to get this bounty, I don't find it fair to gain reputation on something I just copied from another thread. Besides, I should say I don't understand why it works, but installing VS 2015 on the build agent doesn't... – Yan Sklyarenko Sep 28 '15 at 09:30

6 Answers6

49

People using TFS 2012 have reported success using:

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

as arguments to MSBuild. Perhaps this might work for you, but so far this does not work for my TFS 2013 build agents.

Update: I finally got this to work on TFS 2013. Here is what I had to do:

  1. Install VS 2015 or Microsoft Build Tools 2015 (I have both).
  2. Edit my build to use a build process template called TfvcTemplate.12.xaml. I guess that any template newer than this one will do, but the DefaultTemplate.11.1.xaml definitely won't work!)
  3. Set MSBuild arguments to /tv:14.0 I did not have to use the other two I mentioned above.
Lennart
  • 9,657
  • 16
  • 68
  • 84
Marson
  • 806
  • 7
  • 7
  • @Marson I'm having the same exact issue currently. We already have a Custom Build process template. So I'm not sure what I should do with the step 2 ? – J4N Feb 05 '16 at 14:25
  • 3
    @J4N The critical part of step 2 is that the TfvcTemplate.12.xaml uses the Microsoft.TeamFoundation.Build.Activities.RunMSBuild activity instead of the MSBuild activity. If you replace the MSBuild activity with RunMSBuild (which is what I did), you should be fine. – quintessential5 May 16 '16 at 22:38
  • We are using BuildProcessTemplate with custom actions on it. Now is there way or option that we could tweak it to work? – Raajkumar Apr 05 '17 at 22:31
  • using @Vicky - MSFT solution I was able to fix it by changing the ToolVersion and ToolPath property of MSBUILD activity. – Raajkumar Apr 06 '17 at 14:54
  • For me, VSTS 2013 is by default using GitTemplate.12.xaml and when I copy it and open, there is no ToolPath variable on RunMsBuild block. So I tried adding both /tv and /visualstudioversion to 14, but in build logs I still see it using `C:\Program Files (x86)\MSBuild\12.0\bin\amd64\MSBuild.exe` instead of 14.0 – JustAMartin Mar 20 '19 at 13:07
16

It seems that the /tv:14.0 command argument doesn't work as expected. See: BuildActivity ignores ToolsVersion

As a workaround, you need to customize the build process template:

  1. Open the template in Visual Studio and find the Run MSBuild for Project MSBuild activity.
  2. Set ToolVersion to "14.0".
  3. Set ToolPath to target to MSBuild14 (by default: "C:\Program Files (x86)\MSBuild\14.0\Bin").
  4. Check in this build process template and re-queue the build.
Community
  • 1
  • 1
Vicky - MSFT
  • 4,970
  • 1
  • 14
  • 22
  • I had to add ToolVersion and ToolPath to the Arguments myself, but it still doesn't work. (Made copy of DefaultTemplate, applied it to build, made changes per Simon_Weaver's images and your instructions, though had to figure out it was Arguments because it didn't come up on its own when I clicked. Making change to one Run MSBuild for Project made it for both.) – zimdanen Sep 21 '15 at 16:44
  • After you modified the build process template, do you check it in? – Vicky - MSFT Sep 22 '15 at 08:32
  • 9
    Originally this didn't work for me, but I eventually found out that "Run MSBuild For Project" is in the file **twice!** Watch out for that. – aokelly Nov 02 '15 at 23:52
  • 1
    @Plymouth223 do not set ToolVersion. It works without it on my TFS 2012. Set ToolPath only. – Alexander Vasilyev Dec 07 '15 at 12:14
1

If you choose to install VS 2015 on the build machine, there's an important step: open it for first use, and make sure it's licensed. Otherwise, you'll continue to experience build failures.

Jim Roth
  • 399
  • 2
  • 9
1

If you run the DefaultTempalte.11.1.xaml then find the msbuild activity (there are 2 in this template and their label is "Run MSBuild for Project") and change the ToolPath property to the path of the msbuild toolset (for me that was "C:\Program Files (x86)\MSBuild\14.0\Bin").

Nothing else is necessary.

0

If using UpgradeTemplate.xml then just change the "Run TfsBuild for Configuration Folder":

1.Set ToolPath to target to MSBuild14 (by default: "C:\Program Files (x86)\MSBuild\14.0\Bin").

2.Check in this build process template and re-queue the build.

Thanks!

0

The build process determines what build tools version you are using. A vanilla build definition uses the "DefaultTemplate.11.1.xaml" build process template, which is configured to use Build Tools 2013.

The fastest way to fix this is to simply switch to the "TfvcTemplate.12.xaml"

Select Template

If you want to modify the default template, you will need to check it out from $/[Project]/BuildProcessTemplates/DefaultTemplate.11.1.xaml, then edit the Arguments to set the BuildProcessVersion

Edit Build Process Version

Steztric
  • 2,832
  • 2
  • 24
  • 43