I wanted to try out a daily build of Roslyn to see the effect of a recent change to the C# compiler. I know how to do this for older .NET Framework projects, I'd add a reference to Microsoft.Net.Compilers which ships its own copy of csc.exe, however I wasn't sure how to do it for .NET Core projects, so I thought I do a quick write-up of what I found.

Starting Point

<Project Sdk="Microsoft.NET.Sdk">


using System;

class Program
static void Main(string[] args)
static void MyLocalFunction() {};
Console.WriteLine($"Output: {((Action)MyLocalFunction).Method.IsStatic}");

At the time of writing, when running this console app with the C# compiler that ships with .NET Core SDK 3.0.100 it prints...

Output: False

In the latest master of Roslyn I expect this not to be the case.

Add Reference to Microsoft.Net.Compilers.Toolset

It turns out there is a package that does exactly what I need, it includes its own copy of csc and importantly for .NET Core as well as .NET Framework (unlike Microsoft.Net.Compilers). Here it is:

Microsoft.Net.Compilers.Toolset 3.3.1
.NET Compilers Toolset Package. 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. This package requires MSBuild 15.0 and either .NET Destkop 4.…

There are daily builds of this on the Roslyn myget feed. To add it quickly, you can run this command:

dotnet add package Microsoft.Net.Compilers.Toolset --version 3.5.0-beta1-19530-09 --source https://dotnet.myget.org/F/roslyn/api/v3/index.json

Now we should be good to go, let's run our app again...

Output: True