是否可以将CSC CompilerResults
加载到内存中而不是制作.exe
文件?
我用于编译和执行的代码如下(缩短版本):
var provider = new CSharpCodeProvider();
var parameters = new CompilerParameters
{
GenerateExecutable = true,
OutputAssembly = exeName,
GenerateInMemory = false,
TreatWarningsAsErrors = false
};
var compiler = provider.CompileAssemblyFromSource(parameters, code);
private Process process = new Process();
// set parameters of process like filename, use shell execute etc
process.Start();
// do stuff with it like StandardInput.Writeline or StandardOutput.ReadToEnd
process.WaitForExit();
// deleting executed .exe file:
FileInfo file = new FileInfo(process.StartInfo.FileName);
file.Delete();
我的问题是,有什么简便的方法可以将编译后的代码加载到内存中并从内存中执行它,而不是制作.exe
文件,将其作为Process
启动,然后删除该.exe
?< / p>