Using C# 7.1 with MSBuild
Nuget packages
Microsoft.Net.Compilers
nuget package does not work and needn't to be installed.
Set the following project/build settings
Set at least
C# 7.1
or higher in theDebug
andRelease
build properties. (via: Project menu > [ProjectName] Properties > Build tab > [Advanced] button > Language Version).Setting it to latest does not work.
Also make sure that you are running the latest MSBuild version.
Add a reference to the Microsoft.Net.Compilers package (version 2.3.x, to get C# 7.1).
A short description of the package:
Microsoft.Net.Compilers
This package not only includes the C# and Visual Basic compilers, it also modifies MSBuild targets so that the included compiler versions are used rather than any system-installed versions. Once installed, this package requires Microsoft Build Tools 2015.
Make sure you have changed for "All Configuration" and not just "Debug"
else you will be baffling why it is failing at production.