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">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.0</TargetFramework>
</PropertyGroup>
</Project>
DailyRoslyn.csproj
using System
System
;
class Program
Program
{
static void
void
Specifies a return value type for a method that does not return a value.
Main
void Program.Main(string[] args)
(string
string
Represents text as a sequence of UTF-16 code units.
[
string[] args
]
string[] args
args
string[] args
)
{
static void
void
Specifies a return value type for a method that does not return a value.
MyLocalFunction
void MyLocalFunction()
() {};
Console
Console
Represents the standard input, output, and error streams for console applications. This class cannot be inherited.
.WriteLine
void Console.WriteLine(string? value)
Writes the specified string value, followed by the current line terminator, to the standard output stream.
value — The value to write.
IOException — An I/O error occurred.
($"Output: {((Action
Action
Encapsulates a method that has no parameters and does not return a value.
)MyLocalFunction
void MyLocalFunction()
).Method
MethodInfo Delegate.Method
Gets the method represented by the delegate.
A MethodInfo describing the method represented by the delegate.
MemberAccessException — The caller does not have access to the method represented by the delegate (for example, if the method is private).
.IsStatic
bool MethodBase.IsStatic
Gets a value indicating whether the method is .
if this method is ; otherwise, .
}");
}
}
Program.cs

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:

Terminal window
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

Cool!