如何在没有 ILMerge 的情况下将程序集嵌入到控制台应用程序中?
这里有很多关于此的帖子,我正在使用 此代码来自另一篇 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
考虑使用 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.
您还可以查看应用程序虚拟化工具,例如 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.
如果是混合模式程序集,它必须驻留在磁盘上。一些限制什么的。
If it is mixed mode assembly, it has to reside on the disk. Some limitation or something.