2
string code = System.IO.File.ReadAllText(path);
CSharpCodeProvider codeProvider = new CSharpCodeProvider();
CompilerParameters options = new CompilerParameters();
options.GenerateExecutable = false;
options.GenerateInMemory = true;
options.ReferencedAssemblies.Add(Assembly.GetExecutingAssembly().Location);
CompilerResults result;
result = codeProvider.CompileAssemblyFromSource(options, code);
LastErrors = result.Errors;
if (result.Errors.HasErrors)
{
throw new Exception("Compiling the code has returned exceptions!\r\nCheck LastErrors for details.");
}
return result.CompiledAssembly;
是我編譯C#代碼到程序集中的代碼。
但是,我想以某種方式將目錄中的所有文件編譯到該程序集中。使用.NET將多個代碼文件編譯爲程序集?
哇。我很害怕觸摸這些方法,所以我不打算尋找這個方法。謝謝!的xD – Vercas 2011-05-29 11:59:30