Use Roslyn to compile C # code into memory and execute it

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.