a different day a different msbuild issue...

Recently I started working on a small tweak to an existing web project, its a small internal dashboard sort of thing nothing complicated about it.

However after I started working on it I found I could no longer build the project it came up with:
): error CS1525: Invalid expression term 'throw'
): error CS1002: ; expected
 error CS1043: { or ; expected
 error CS1513: } expected
: error CS1014: A get or set accessor expected
: error CS1513: } expected
 When I looked at the location of the build errors I could see some perfectly valid code, all be it C#7:

 public IEnumerable<AttemptResult> Attempts
{
get => _attempts;
set => _attempts = (value ?? Enumerable.Empty<AttemptResult>());
}

Why would it not like the C#7 code, i'm in VS2017 it should all be correct, when I double checked the language setting under Advanced Build Settings it correctly had C# latest major version, so it wasn't a case the project had got pinned to a language version.

I next turned to the build log to see what was happening and noticed something odd:
The core compile was using
c:\repositories\xxxx\packages\Microsoft.Net.Compilers.1.0.0\build\..\tools\csc.exe /noconfig /nowarn:1701,1702,2008 /nostdlib+ /errorreport:prompt /warn:4 /define:TRACE /errorendlocation /preferreduilang:en-US  etc...

This wasn't pointing at roslyn compiler unlike normal projects which always use:
 C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\Roslyn\csc.exe /noconfig /nowarn:1701,1702,2008 /nostdlib+ /errorreport:prompt

So i inspected my nuget packages for the project and found it was using Microsoft.Net.Compiles and in its description i says:
 Referencing this package will cause the project to be built using the specific version of the C# and Visual Basic compilers contained in the package, as opposed to any system installed version.
The project referenced version 1 which was released in 2015, definitively before C#7 was a thing. I followed the link in the Nuget package to get to the Rosyln GitHub page which details the NuGet packages and what each version means.  

I was correct C#7 wasn't a thing until V2, so i can update the package and get it working. However I was puzzled as to why it was even referenced ... turns out I have no idea! Nothing was actually dependent on it, however we used to have Application Insights in the project so it might have been left over from then.

A problem solved and a lesson learnt for the future :)

Comments

Popular posts from this blog

WebUSB - An unexpected update...

Can you use BuildRoot with Windows Subsystem for Linux......

DotNet CLI , private NuGet feeds and Linux...