How to Compile the .cs file into .dll in C#.Net programatically?

前端 未结 2 1571
感动是毒
感动是毒 2021-01-29 16:48

Can any one help me in converting the .cs file into .dll programmatically?

2条回答
  •  抹茶落季
    2021-01-29 16:58

    You're looking for the CSharpCodeProvider class.

    For example:

    var compiler = new CSharpCodeProvider(new Dictionary { { "CompilerVersion", "v4.0" } });
    var options = new CompilerParameters { OutputAssembly = path);
    var results = compiler.CompileAssemblyFromFile(options, sourceFile);
    

提交回复
热议问题