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>using SystemSystem;
class ProgramProgram{ static voidvoidSpecifies a return value type for a method that does not return a value. Mainvoid Program.Main(string[] args)(stringstringRepresents text as a sequence of UTF-16 code units.[string[] args]string[] args argsstring[] args) { static voidvoidSpecifies a return value type for a method that does not return a value. MyLocalFunctionvoid MyLocalFunction()() {}; ConsoleConsoleRepresents the standard input, output, and error streams for console applications. This class cannot be inherited..WriteLinevoid Console.WriteLine(string? value)Writes the specified string value, followed by the current line terminator, to the standard output stream.Parametersvalue — The value to write.ExceptionsIOException — An I/O error occurred.($"Output: {((ActionActionEncapsulates a method that has no parameters and does not return a value.)MyLocalFunctionvoid MyLocalFunction()).MethodMethodInfo Delegate.MethodGets the method represented by the delegate.ReturnsA MethodInfo describing the method represented by the delegate.ExceptionsMemberAccessException — The caller does not have access to the method represented by the delegate (for example, if the method is private)..IsStaticbool MethodBase.IsStaticGets a value indicating whether the method is .Returnsif this method is ; otherwise, .}"); }}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:
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.jsonNow we should be good to go, let’s run our app again…
Output: True
Cool!
Comments