c# - 使用.NET 将多个代码文件编译成程序集?

标签 c# .net

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# 代码编译成程序集的代码。
但相反,我想以某种方式将目录中的所有文件编译到该程序集中。

最佳答案

你能不能只用CompileAssemblyFromFile反而?这允许您指定多个文件名。

关于c# - 使用.NET 将多个代码文件编译成程序集?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6167567/

相关文章:

c# - 如何根据第一条折线转换第二条折线

c# - UpdateResource 不适用于 lpType 作为字符串

.NET ORM、不可变值对象、结构、默认构造函数和只读属性

c# - ThreadPool - WaitAll 64 句柄限制

c# - 如何将 Excel 工作表导出到新工作簿

C# 调试器拦截来自 native DLL 的 WriteConsole 事件

c# EnumerateFiles 通配符返回不匹配?

c# - 当我在 TextChanged 事件中运行相同的代码而不是在 Button Click 中运行相同的代码时,为什么会得到不同的结果?

c# - 我有大量 GUID 和其他数据需要从中提取子集,最快的方法是什么?

c# - 将多个属性组合为单个属性 - 合并属性