I work on existing Windows form application (wasn't created by me) which can run C# scripts. The application uses .net Framework 4.7.2, compiled in AnyCPU mode.
It uses Microsoft.CodeDom.Providers.DotNetCompilerPlatform NuGet package version 3.6.0 (the latest stable available). It also uses it's own Roslyn compiler of some old version unknown to me:
The application works, scripts are compiled and run. But only the old C# syntax is supported. I'd like to upgrade C# compiler to use C# 7.
I see that DotNetCompilerPlatform package is installed with its own set of C# compilers. The one in tools\Roslyn46 folder has file version 2.10.0.0 (a bit newer than the one currently used), and the one in Roslyn472 has file version 3.600.20.26904.
Ok, I copy the files from Roslyn472 to my output folder (like it was done with older version) and set a path to it. The rest I don't change. When CSharpCodeProvider.CompileAssemblyFromFile is called, the result has no errors or warnings, but no assembly is created at all.
Inspecting the result class I can also see the command line generated and I'm not sure it is even compatible with that version of csc.exe, because when I try to run it manually it complains about unknown parameters which can be for a previous version. In particular it doesn't like /t:library switch.
Below is an extract of the code, compiling scripts:
class CompilerSettings : IProviderOptions
{
// ...
public string CompilerFullPath => "path to csc.exe";
}
...
engine = new CSharpCodeProvider( new CompilerSettings() );
parameters = new CompilerParameters
{
WarningLevel = 3,
GenerateInMemory = false,
GenerateExecutable = false,
OutputAssembly = @"c:\dev\CompiledScript.dll",
IncludeDebugInformation = true
};
// Add some references:
foreach ( string entry in _references )
parameters.ReferencedAssemblies.Add( entry );
...
// files list assembled in advance.
result = engine.CompileAssemblyFromFile( parameters, files );
Any idea which version of compiler should be used? Or maybe there are some options which need to be added.