2010-07-22 66 views

回答

1

下面的代码将允许您使用codedom编译代码,然后可以显示用户代码是否正确编译。它甚至还创建了一个DLL。

感谢 亚历克斯

// Store provider from the method into a object, Default is CSharpCodeProvider** 
CodeDomProvider provider = this.GetCurrentProvider(); 

// Configure a CompilerParameters that links System.dll** 
String[] referenceAssemblies = { "System.dll", "System.Data.Linq.dll", "System.Web.dll","System.XML.dll","System.ComponentModel.DataAnnotations.dll", "System.Data.dll", _mvcLocation }; 

CompilerParameters cp = new CompilerParameters(referenceAssemblies, this.fileLocation + this.fileName + ".dll", false); 

// Generate an executable rather than a DLL file.** 

cp.GenerateExecutable = true; 

// Invoke compilation.** 
CompilerResults _results = provider.CompileAssemblyFromFile(cp, this.fileLocation + this.fileName + "." + this.extention); 
相关问题