我刚刚使用 codeDom 生成了 .cs 文件。有人可以解释我如何执行它吗?
问问题
591 次
2 回答
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);
于 2011-03-30T11:38:31.763 回答