Visual Studio 2010 c# winforms 运行时编译

发布于 2024-10-31 15:26:31 字数 650 浏览 3 评论 0原文

我有以下问题,将尝试尽快描述它。

在我的程序中,可以通过单击按钮将 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

对不⑦ 2024-11-07 15:26:31

如果您始终使用同一组类,则值得将这些公共类放入类库中,并从动态编译的代码中引用它们。

如果它们在每种情况下都不相同,则很难看到您期望的改进 - 如果必须编译那么多代码,就必须编译它,并且有那么多代码可能会出现错误在其中。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文