I would like to use the Microsoft.CSharp.CSharpCodeProvider class to compile C# 7.3 code. The compiler version is specified in an IDictionary that is taken as input when a new CSharpCodeProvider is created; for example, { "CompilerVersion", "v4.0" }. "v4.0" is not sufficient, as it does not recognize v7.3 as a compiler option.
The newer compiler versions are no longer shipped as part of the .NET Framework proper, and therefore cannot be by default accessed via the legacy CodeDOM API (which includes Microsoft.CSharp.CSharpCodeProvider
).
Instead if you wish to use the CodeDOM API with the newer compilers, you want to use Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider
which is a subclass of Microsoft.CSharp.CSharpCodeProvider
. This class is available in the Microsoft.CodeDom.Providers.DotNetCompilerPlatform nuget package.
For non web applciations you also need to provide a configuration or environment variable that provides a path to C# compiler you want to use (A copy ships in the nuget package, so you can use that). See https://github.com/aspnet/RoslynCodeDomProvider for details.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With