2010-07-22 3 views

ответ

0

Это не совсем так просто. See here для праймера. В основном CodeDom поддерживает такие сценарии, как code generation and dynamic compilation. Файлы .cs, созданные с помощью CodeDom, не являются исполняемыми в обычном смысле.

1

Код, приведенный ниже, позволит вам скомпилировать код с помощью кодированного кода, а затем вы можете показать пользователю, правильно ли скомпилирован код. Он даже создает DLL.

Благодаря Alex

// 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); 
Смежные вопросы