Dynamically compile multiple files into assembly using Rosyln

Viewed 858

I've recently seen using CSharpCodeProvider is deprecated in .NET Core 5. I was wondering if there was a smart way to combine multiple files into one dll from which I can load up using Rosyln instead. I'd hate to have to stick with .NET Framework 4.7 as this is a big part of a program I'm working on.

My code used to be pretty much just this

string Files[] = Directory.GetFiles("xxxxx/bin/Debug/net5.0/Scripts", ".cs");
Parameters = new CompilerParameters(new string[1] {"xxxxx/bin/Debug/net5.0/Program.dll"}, "xxxxx/bin/Debug/net5.0/Scripts/Output/Scripts.dll");
return new CSharpCodeProvider().CompileAssemblyFromFile(Parameters, Files).CompiledAssembly;

What would be the most efficient way to do this in Rosyln?

Reference: https://github.com/dotnet/runtime/issues/18768#issuecomment-265381303 (PlatformNotSupportedException)

1 Answers
Related