-1

我刚刚使用 codeDom 生成了 .cs 文件。有人可以解释我如何执行它吗?

4

2 回答 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 回答
0

这不是那么简单。请参阅此处了解入门知识。CodeDom 基本上支持 代码生成和动态编译等场景。因此,使用 CodeDom 创建的 .cs 文件不是通常意义上的可执行文件。

于 2010-07-22T04:33:39.160 回答