Compile assembly in runtime and save dll in a folder

独自空忆成欢 提交于 2019-11-29 12:34:44

You could use the OutputAssembly property of CompilerParameters to sets the name (path) of the output assembly. From your example:

...
CompilerParameters compilerparams = new CompilerParameters();
compilerparams.GenerateInMemory = false;

compilerparams.OutputAssembly = "OutputAssembly.dll";

CompilerResults results = compiler.CompileAssemblyFromSource(compilerparams, code);
...

With OutputAssembly property you can specify just the assembly name. The Assembly will be created in current directory. If you need to specify the full path you have to set the compiler options string in this way:

System.CodeDom.Compiler.CompilerParameters parameters = new CompilerParameters();
 parameters.GenerateExecutable = false;
 parameters.CompilerOptions = " /out:C:\\Temp\\" + outputAssemblyFile;

Look here, many options can be set in this property. If you set CompilerOptions then OutputAssembly property will be ignored.

I hope this can help.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!