8
A
回答
10
要编译文件在运行,你需要做沿着这些线路(如源代码是方含代码编译字符串)的东西:
CodeDomProvider codeProvider = new CSharpCodeProvider();
ICodeCompiler compiler = codeProvider.CreateCompiler();
// add compiler parameters
CompilerParameters compilerParams = new CompilerParameters();
compilerParams.CompilerOptions = "/target:library /optimize";
compilerParams.GenerateExecutable = false;
compilerParams.GenerateInMemory = true;
compilerParams.IncludeDebugInformation = false;
compilerParams.ReferencedAssemblies.Add("mscorlib.dll");
compilerParams.ReferencedAssemblies.Add("System.dll");
// compile the code
CompilerResults results = compiler.CompileAssemblyFromSource(compilerParams, sourceCode);
4
您可以使用CSharpCodeProvider合理轻松地进行编译。您可以从C# in Depth web site下载我的snippet编译器Snippy的源代码。这使用CSharpCodeProvider,所以你可以使用它作为示例代码。
相关问题
- 1. 程序集加载时有没有办法运行代码?
- 2. 有没有办法强制类在运行时加载
- 3. 有没有办法在运行时加载类jar和包?
- 4. 有没有办法在运行时将布局添加到Android应用程序?
- 5. 有没有办法将6502程序集添加到Google Code Prettify?
- 6. 关于itunes com sdk,有没有办法将文件加载到应用程序
- 7. 有没有办法强制MonoDevelop构建/加载程序集?
- 8. 有没有办法在JVM中查找加载的类文件?
- 9. 有没有办法将大文本文件逐行加载到kdb中?
- 10. 有没有办法将节点添加到正在运行的Hadoop集群?
- 11. 有没有办法卸载或重新加载当前加载的运行时?
- 12. Typhoon DI:有没有什么办法在运行时按类名找到程序集?
- 13. 运行时错误:无法加载文件或程序集
- 14. PowerShell运行时异常 - “无法加载文件或程序集”
- 15. 有没有办法将事件处理程序附加到C#中正在运行的进程列表?
- 16. 有没有办法从卸载程序文件中禁用autouninstaller?
- 17. ,有没有办法在运行时确定类的成员?
- 18. 有没有办法在运行时获取类的字节码?
- 19. 有没有办法在失败时重新运行测试类
- 20. 有没有办法直接在WPF应用程序中运行winforms exe文件?
- 21. 有没有办法将非silverlight程序集添加到silverlight项目中?
- 22. 有没有办法在运行时在Android中随意加载资源?
- 23. 在运行时加载的程序集
- 24. 在运行时加载程序集
- 25. 有没有办法在集成应用程序池中运行wcf3.5 rest api
- 26. 有没有办法在Raspberry Pi上运行Angular应用程序?
- 27. 有没有办法在android上运行windows mobile应用程序?
- 28. 有没有办法将powerbuilder应用程序导出到文本?
- 29. 有没有办法让python应用程序无法运行?
- 30. 有没有办法在运行时重新加载Tomcat的连接池?