4

I've seen a couple .net applications that allow you to select a C# .cs source file and the program itself will compile this code and run it.

How is this done?

4 Answers 4

11

It probably uses the CSharpCodeProvider class in the Microsoft.CSharp namespace. You would want to look at the following methods to compile code:

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

Comments

2

CodeDOM is your friend

Comments

1

MSDN has a great series of articles explaining this...

http://msdn.microsoft.com/en-us/library/650ax5cx.aspx

Comments

0

My guess is by explicitly calling the csc.exe compiler. Keep in mind that this and any dependencies would have to be included with your deployment.

You can take a look at CS-Script which interprets C# files. Its free but not open sources though...

Comments

Your Answer

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