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/