如何在没有 ILMerge 的情况下将程序集嵌入到控制台应用程序中?

发布于 2024-08-24 10:11:22 字数 682 浏览 4 评论 0原文

这里有很多关于此的帖子,我正在使用 此代码来自另一篇 SO 帖子,并将委托分配放入我的 Main() 方法中。其他帖子都没有直接回答我的问题。

我已经将第三方程序集作为资源嵌入,但是当我启动应用程序时:

  • 我收到一个带有 FileNotFoundException 内部的 TypeInitializationException 。它试图在文件系统上查找程序集但失败。
  • 它永远不会到达 Main 方法,在该方法中分配了 AssemblyResolve 的事件处理程序

我有两个程序集引用嵌入在我的 Resources.resx 中,一个是第三方工具(命令行解析器),另一个是库文件,其中应用程序的核心所在。

也许这对于控制台应用程序来说是不可能的?似乎不太可能,但我没有找到解决办法。

回复:ILMerge 等: 我想完全用代码完成此操作,而不涉及任何工具。原因:我不希望存储库中的源代码需要其他团队成员安装他们可能还没有的工具。如果这不可能,那么 ILMerge 看起来是下一个最佳选择。

There are a lot of posts on here about this, I'm using this code from another SO post and placing a delegate assignation in my Main() method. None of the other posts have directly answered my question.

I've got my third party assembly embedded as a resource but when I fire up the app:

  • I'm getting a TypeInitializationException with an inner of FileNotFoundException. It's trying to find the assembly on the file system and failing.
  • it's never getting to the Main method, where the event handler for AssemblyResolve is assigned

I have two assembly refs that are embedded in my Resources.resx, one is a third party tool (command line parser) and the other is a Library file where the meat of the application resides.

Maybe this isn't possible with a console app? Seems unlikely but I don't see a way around it.

Re: ILMerge etc: I'd like to get this done entirely in code without involving any tools. Reason: I don't want to have source code in the repository that requires other team members to install a tool that they probably don't have already. If that's not possible then ILMerge looks like the next best option.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

誰ツ都不明白 2024-08-31 10:11:22

考虑使用 ILMerge 将程序集合并为一个,而不是作为资源嵌入。这是 ILMerge 的下载站点

您可以将第三方程序集合并到控制台应用程序中。

Consider using ILMerge to merge the assemlies into one rather than embedding as a resource. This is download site for ILMerge.

You would merge your third party assemblies into your console app.

执笔绘流年 2024-08-31 10:11:22

您还可以查看应用程序虚拟化工具,例如 XenoCode。他们可以将多个程序集(包括 .net 框架本身)打包成独立的可执行文件。

You could also look at application virtualization tools like XenoCode. They can package multiple assemblies (including the .net framework itself) into a stand alone executable.

阪姬 2024-08-31 10:11:22

如果是混合模式程序集,它必须驻留在磁盘上。一些限制什么的。

If it is mixed mode assembly, it has to reside on the disk. Some limitation or something.

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