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;
Run Code Online (Sandbox Code Playgroud)
是我将C#代码编译成程序集的代码.
但相反,我想以某种方式将目录中的所有文件编译到该程序集中.
| 归档时间: |
|
| 查看次数: |
1313 次 |
| 最近记录: |