run time compiling of c# code

S

Steve Richter

my app needs to be able to receive c# source code from a trusted
remote system, compile that c# code, then run it.

assuming the way to do this is to use the Process class:
Process p = new Process( ) ;
p.StartInfo.FileName = "csc.exe" ;
p.StartInfo.Arguments = "csc command line string" ;
p.Start( ) ;
p.WaitForExit( ) ;

do I need to, how do I first run the SDKVARS.BAT file?

how do I set the directories so that the sdkvars.bat and csc.exe files
will reliably be found?

searching this group I read a post saying "c# has an in memory
compiler that can be used". Is there a way to compile c# code w/o
having to spawn the csc.exe process?

thanks,

-Steve
 
D

DeveloperX

my app needs to be able to receive c# source code from a trusted
remote system, compile that c# code, then run it.

assuming the way to do this is to use the Process class:
Process p = new Process( ) ;
p.StartInfo.FileName = "csc.exe" ;
p.StartInfo.Arguments = "csc command line string" ;
p.Start( ) ;
p.WaitForExit( ) ;

do I need to, how do I first run the SDKVARS.BAT file?

how do I set the directories so that the sdkvars.bat and csc.exe files
will reliably be found?

searching this group I read a post saying "c# has an in memory
compiler that can be used". Is there a way to compile c# code w/o
having to spawn the csc.exe process?

thanks,

-Steve

There's a reasonable tutorial here: http://www.divil.co.uk/net/articles/plugins/scripting.asp
and I'm sure there was one on codeproject but I can't find it.
 
N

Nicholas Paldino [.NET/C# MVP]

Steve,

Is this for .NET 2.0 or for .NET 1.1 and before? If the answer is the
former, then you can set references to the MSBUILD libraries and then use
that to compile your code. You can create project files dynamically and
have MSBUILD do all the work for you.

Hope this helps.
 
A

Andy

Is this for .NET 2.0 or for .NET 1.1 and before? If the answer is the
former, then you can set references to the MSBUILD libraries and then use
that to compile your code. You can create project files dynamically and
have MSBUILD do all the work for you.

Wouldn't a better solution be to use the System.Reflection.Emit
namespace?
 
N

Nicholas Paldino [.NET/C# MVP]

Andy,

No, as the OP stated, the code is already written. He is loading the
code and then wants to compile it. He isn't generating a dynamic assembly
from logic that is executing in his program (which is where the
System.Reflection.Emit namespace would come in handy).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top