开发者

Compile multiple code files into an assembly with .NET?

开发者 https://www.devze.com 2023-03-08 21:20 出处:网络
string code = System.IO.File.ReadAllText(path); CSharpCodeProvider codeProvider = new CSharpCodeProvider();
string code = System.IO.File.ReadAllText(path);

CSharpCodeProvider codeProvider = new CSharpCodeProvider();

CompilerParameters options = new CompilerParameters();
option开发者_开发百科s.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;

is my code for compiling C# code into an assembly.

But instead, I would like to somehow compile all the files in a directory into that assembly.


Can you not just use CompileAssemblyFromFile instead? That allows you to specify multiple filenames.

0

精彩评论

暂无评论...
验证码 换一张
取 消