ILMerge 和 .NET 4.0 存在严重问题
在我的一生中,我似乎无法将我的 .NET 4 应用程序与 ILMerge 正确合并。即使在设置 /targetplatform、/lib、/ndebug 并添加自定义 ILMerge.exe.config 文件后,输出文件也无法正常工作(它似乎无法“找到”合并库)。
我已经尝试过这个和此无济于事。除非使用配置文件,否则我什至无法构建它,但是当我这样做时,它不起作用。如果没有配置文件,我总是收到错误消息“不允许未解析的程序集引用:PresentationFramework”。
这是我的 ILMerge 命令用作构建后事件的当前状态:
ilmerge.exe /out:C:\Users\Logan\Development\Projects\OrangeNote\OrangeNote\bin\Release\OrangeNote.exe
/ndebug /targetplatform:v4,C:\Windows\Microsoft.NET\Framework\v4.0.30319
/lib:"C:\Windows\Microsoft.NET\Framework\v4.0.30319"
/lib:"C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\PublicAssemblies"
"C:\Users\Logan\Development\Projects\OrangeNote\OrangeNote\obj\Release\OrangeNote.exe"
"C:\Users\Logan\Development\Projects\OrangeNote\OrangeNote\..\..\..\Libraries\Lucene.Net\src\Lucene.Net\bin\Release\Lucene.Net.dll"
"C:\Users\Logan\Development\Projects\OrangeNote\OrangeNote\..\..\..\Libraries\Ookii.Dialogs\src\Ookii.Dialogs.Wpf\bin\Release\Ookii.Dialogs.Wpf.dll"
"C:\Users\Logan\Development\Projects\OrangeNote\OrangeNote\..\..\..\Libraries\SharpZipLib\bin\ICSharpCode.SharpZipLib.dll"
"C:\Users\Logan\Documents\Visual Studio 2010\Projects\HumanInterfaceProject\HumanInterfaceProject\bin\Release\HipLib.dll"
对我做错了什么有什么想法吗?
For the life of me, I can't seem to get my .NET 4 application merging properly with ILMerge. Even after setting /targetplatform, /lib, /ndebug and adding a custom ILMerge.exe.config file the output file doesn't work properly (it doesn't seem to be able to "find" the merged libraries).
I've tried this and this to no avail. I can't even get it to build unless I use the config file, but when I do it doesn't work. Without the config file, I consistently get the error message "Unresolved assembly reference not allowed: PresentationFramework".
Here is the current state of my ILMerge command being used as a post build event:
ilmerge.exe /out:C:\Users\Logan\Development\Projects\OrangeNote\OrangeNote\bin\Release\OrangeNote.exe
/ndebug /targetplatform:v4,C:\Windows\Microsoft.NET\Framework\v4.0.30319
/lib:"C:\Windows\Microsoft.NET\Framework\v4.0.30319"
/lib:"C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\PublicAssemblies"
"C:\Users\Logan\Development\Projects\OrangeNote\OrangeNote\obj\Release\OrangeNote.exe"
"C:\Users\Logan\Development\Projects\OrangeNote\OrangeNote\..\..\..\Libraries\Lucene.Net\src\Lucene.Net\bin\Release\Lucene.Net.dll"
"C:\Users\Logan\Development\Projects\OrangeNote\OrangeNote\..\..\..\Libraries\Ookii.Dialogs\src\Ookii.Dialogs.Wpf\bin\Release\Ookii.Dialogs.Wpf.dll"
"C:\Users\Logan\Development\Projects\OrangeNote\OrangeNote\..\..\..\Libraries\SharpZipLib\bin\ICSharpCode.SharpZipLib.dll"
"C:\Users\Logan\Documents\Visual Studio 2010\Projects\HumanInterfaceProject\HumanInterfaceProject\bin\Release\HipLib.dll"
Any thoughts on what I'm doing wrong??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我见过的用于在 WPF 中组合 .dll 的一项建议是简单地将 dll 添加为项目的嵌入式资源,然后以编程方式将 dll 加载到程序集中。
看:
http://blogs.msdn.com/b/microsoft_press/archive/2010/02/03/jeffrey-richter-excerpt-2-from-clr-via-c-third-edition.aspx
One suggestion I have seen used to combine .dlls in WPF is to simply add the dll as an embedded resource the the project and then programatically load the dll into the assembly.
see:
http://blogs.msdn.com/b/microsoft_press/archive/2010/02/03/jeffrey-richter-excerpt-2-from-clr-via-c-third-edition.aspx
你可以试试科斯特拉。
https://github.com/Fody/Costura#how-it-works
它基本上需要 Jeffrey Richters 方法
http://blogs.msdn.com/b/microsoft_press/archive/2010/02/03/jeffrey-richter-excerpt-2-from-clr-via-c-third -edition.aspx
但是以一种不需要编写任何代码的方式实现。即您不需要编写“AssemblyResolve”方法
You could try Costura.
https://github.com/Fody/Costura#how-it-works
It basically takes Jeffrey Richters appraoch
http://blogs.msdn.com/b/microsoft_press/archive/2010/02/03/jeffrey-richter-excerpt-2-from-clr-via-c-third-edition.aspx
But does it in a way that you dont need to write any code. ie you dont need to write the "AssemblyResolve" method
我给 ILMerge 的作者 Mike Barnett 发了电子邮件,他解释说,不幸的是,它根本不是为与 WPF 应用程序一起使用而设计的,当我告诉他我可以将它与我的 WPF 3.5 应用程序一起使用时,他感到很惊讶。由于它并没有得到真正的支持,所以我现在就将其注销并等待另一个替代方案的出现。
附带说明一下,我确实尝试了 Eziriz 的 .NET Reactor,它实际上效果很好,但价格为 180 美元对于一个爱好项目,我还不太愿意花钱。但这比红门的其他商业替代品便宜很多,所以我想提一下。
更新:Mike Barnett 现在认为此问题的公认答案是最佳解决方案。据他说,如果他知道这是可能的,他一开始就不会编写 ILMerge。
I emailed Mike Barnett, the author of ILMerge and he explained it's not designed to work with WPF apps at all, unfortunately, and was surprised when I told him that I had it working with my WPF 3.5 app. Since it's not really supported, I'll just write this off for now and wait for another alternative to present itself.
As a side note, I did try out .NET Reactor from Eziriz, and it actually worked great, but costs $180 which for a hobby project I'm not really willing to spend just yet. But that's a whole lot cheaper than the other commercial alternative from Red Gate and so thought I'd mention it.
Update: Mike Barnett now considers the accepted answer to this question as the best solution. According to him, if he'd known it was possible, he never would have written ILMerge in the first place.
虽然 ILMerge 确实不会更新 WPF 资源字符串,但它可用于通过将引用程序集目录而不是运行时目录传递到
/targetplatform
,例如:/targetplatform:v4,"C:\Program Files\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\Profile\Client"
(对于 .NET 4.0 客户端配置文件)。我用它来合并 Rx 的 System.Reactive.dll,它引用了 Dispatcher,但没有任何实际的 WPF 资源。
While it is true that ILMerge does not update WPF resource strings, it can be used to merge assemblies with WPF references by passing the reference assembly directory instead of the runtime directory to
/targetplatform
, as such:/targetplatform:v4,"C:\Program Files\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\Profile\Client"
(for the .NET 4.0 client profile).I use this to merge in Rx's System.Reactive.dll, which has a reference to
Dispatcher
, but doesn't have any actual WPF resources.我注意到您的程序集名为“dialogs.wpf”。目前,ILMerge 无法正确地将程序集与其中的 WPF 资源合并。
关于此的信息不多,但是 此论坛帖子提到了一种可能的解决方案,这个问题的答案,但投票最高的建议是购买商业替代品 - 我不知道这对你来说是否可行。
此处的讨论解释了原因它不起作用,并且有一个建议 此处更改 xaml 中的资源引用可能有助于解决问题。
I noticed that one your your assemblies is called "dialogs.wpf". Currently ILMerge does not correctly merge assemblies with WPF resources in them.
There isn't much info around on this, but this forum post mentions a possible solution, and there are several possibilities mentioned on answers to this question, but the highest voted suggestion is just to buy a commercial alternative - I don't know if that is a possibility for you.
There is a discussion here that explains why it doesn't work, and there is a suggestion here that changing the resource reference in the xaml may help solve the problem.