Tugberk Ugurlu in his blog "Compiling C # Code into Memory and executing It with Roslyn" to introduce a use. NET Next generation compiler (or compiler Service)--roslyn tips. That is, the C # code is compiled into memory (not saved to a file), and the code executes.
Simply put, is to install Microsoft.CodeAnalysis.CSharp this NuGet package first, then call the Roslyn API in code, then output the code to a MemoryStream, and then load the compiled assembly from memory to execute it.
One of the benefits of this technique is that you can quickly validate, analyze, and even integrate your own code into the CI process (future CI not only performs unit tests, but also code analysis).
Original address: Http://www.tugberkugurlu.com/archive/compiling-c-sharp-code-into-memory-and-executing-it-with-roslyn
Use Roslyn to compile C # code into memory and execute it