Visual Studio 2010 c# winforms 运行时编译
我有以下问题,将尝试尽快描述它。
在我的程序中,可以通过单击按钮将 winform 编译为 .exe。
现在我尝试使用 CodeDom 来完成此操作,因此在我的程序中我有以下行:
CompilerResults results = codeProvider.CompileAssemblyFromSource(parameters, text);
其中 codeProvider 是 CodeDomProvider,text 是编译源。
问题是我需要保存为 .exe 的 winform 背后有一个使用其他类和表单的类,并且由于参数“text”是一个字符串参数,它必须包含所有这些类,这会导致大量的代码,更不用说还有很多错误了。 此处 就是我的意思的一个例子。
肯定还有其他方法,问题是,它们是什么?提前致谢!
I have the following problem, will try to describe it shortly.
In my program there is to be a possibility to compile a winform to an .exe by clicking on a button.
Now I tried to do it with CodeDom, so in my program I have the following line:
CompilerResults results = codeProvider.CompileAssemblyFromSource(parameters, text);
where codeProvider is CodeDomProvider and text is the source from where to compile.
Problem is the winform I need to save as an .exe has a class behind it that uses other classes and forms, and, since parameter 'text' is a string parameter, it has to include all those classes, which results in HUGE amount of code, not to mention plenty of mistakes. Here's an example of what I mean.
There must be other ways, question is, what are they? Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您始终使用同一组类,则值得将这些公共类放入类库中,并从动态编译的代码中引用它们。
如果它们在每种情况下都不相同,则很难看到您期望的改进 - 如果必须编译那么多代码,就必须编译它,并且有那么多代码可能会出现错误在其中。
If you always use the same set of classes, it would be worth putting those common classes in a class library, and referring to that from the dynamically compiled code.
If they're not the same in every case, it's hard to see improvements you expect - if that much code has to be compiled, it has to be compiled, and there's that much code which can have mistakes in it.