3

Is there a managed API to compile C# applications (to memory or disk)? I assume one exists because SharePoint compiles ASP.NET pages in memory. We want to use it to, at runtime, generate Linq DataContexts and compile those against various projects.

2 Answers 2

3

Take a look at the Microsoft.CSharp.CSharpCodeProvider class. That page has sample code how to use that class to compile C# sources.

Note: This class cannot be use in partial trust. You need to run with full trust in order to be able to run the C# compiler.

Sign up to request clarification or add additional context in comments.

Comments

1

As Franci has pointed out, the CSharpCodeProvider is what you want.

While writing my C# book I built "Snippy" which is a quick'n'dirty way of building and running snippets of C# - it's a simple enough project to make it quite easy to see how to use CSharpCodeProvider. The full source is available - take a look.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.