Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TeamCity C# compile error: Invalid expression term 'int'

A project that compiles locally (targeting .NET Framework 4.6.1) fails on TeamCity with the following message:

[CoreCompile] Csc [Csc] Using shared compilation with compiler from directory: C:\Program Files (x86)\MSBuild\14.0\bin

[19:02:15][Csc] Services\MyFile.cs(20, 55): error CS1525: Invalid expression term 'int'

[19:02:15][Csc] Services\MyFile.cs(20, 59): error CS1003: Syntax error, ',' expected

I also get a lot of these in the failed compile in red writing:

[Step 5/9] The target "MvcBuildViews" listed in a BeforeTargets attribute at "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\Web\Microsoft.Web.Publishing.targets (845,131)" does not exist in the project, and will be ignored.

like image 364
Frederik Struck-Schøning Avatar asked May 15 '17 17:05

Frederik Struck-Schøning


1 Answers

Firstly, if it might help anybody, when TeamCity fails a step, a lot of text in that step will be red in color (even mere warnings), so at first I ran into a dead-end with believing the second error message was the problem. It wasn't.

Turns out, my Resharper 2016.3.2 (on Visual Studio 2017) had changed the following

int newInt;
if (!int.TryParse(theChar.ToString(), out newInt))
    return false;

into

if (!int.TryParse(theChar.ToString(), out int newInt))
    return false;

via an Alt+Enter refactoring called "Inline variable declaration" (which normally sounds pretty harmless) and I was like, well, ok then.

This was not causing any trouble locally, since it's a c# 7 syntax thing, but on my TeamCity build-agent the compiler would fail because of too low version of MSBuild.

like image 52
Frederik Struck-Schøning Avatar answered Sep 28 '22 04:09

Frederik Struck-Schøning