如何合并 WPF 应用程序的程序集?
我尝试在基于 WPF 的项目(VS2010、Net4.0)上使用 ILMerge,但无法运行合并的可执行文件。所以我创建了两个非常简单的项目,
- 只是一个控制台应用程序,它打印出 hello world
- wpf 应用程序,该应用程序显示带有 hello world 标签的窗口
编译每个项目后,我得到单个可执行文件(因此合并,并没有真正合并任何内容,它只是用于测试) 。每个可执行文件当然都可以工作。
然后我以这种方式“合并”每个可执行文件:(
"C:\Program Files\Microsoft\ILMerge\ilmerge"
/targetplatform:v4,c:\Windows\Microsoft.NET\Framework\v4.0.30319
/lib:c:\Windows\Microsoft.NET\Framework\v4.0.30319\wpf
/out:Merged.exe MyApplication.exe
我进行多行调用只是为了提高可读性)。好的,现在控制台应用程序已合并并且运行得像以前一样好,wpf 应用程序已合并,没有任何错误,但我无法运行它。我的意思是,我输入
Merged.exe
任务栏闪烁,但没有显示任何内容 - 没有窗口,没有错误,什么也没有。
那么我应该如何合并WPF应用程序呢?
I tried to use ILMerge on my WPF-based project (VS2010, Net4.0) but I couldn't make the merged executable to run. So I created two very simply projects
- just a console application which prints out hello world
- wpf application which shows window with hello world label
After compiling each project I get single executable file (so merging, does not really merge anything, it is just for test). Each executable works of course.
Then I "merge" each executable this way:
"C:\Program Files\Microsoft\ILMerge\ilmerge"
/targetplatform:v4,c:\Windows\Microsoft.NET\Framework\v4.0.30319
/lib:c:\Windows\Microsoft.NET\Framework\v4.0.30319\wpf
/out:Merged.exe MyApplication.exe
(I made the call multiline just for SO readability). Ok, now console application is merged and runs as fine as before, the wpf application is merged without any errors but I cannot run it. I mean, I type
Merged.exe
Taskbar blinks, but nothing shows up -- no window, no error, nothing.
So how should I merge WPF app?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
据我所知(并且经历过),ilmerge 无法与嵌入了 xaml 资源的 WPF 程序集正常工作。
请参阅此问题以获取一些可能的解决方案/替代方案
From what I know (and have experienced) ilmerge does not work correctly with WPF assemblies that have xaml resources embedded.
See this question for some possible solutions/alternatives
如果我理解正确的话,您希望将所有程序集嵌入到一个 exe 中。
有一个令人惊叹的 NuGet 包,名为 Costura.Fody。合并程序集再简单不过了!
如果您需要合并资源 DLL,那么您很幸运!还有另一个扩展 Costura.Fody 的 NuGet,称为 Resource.Embedder!
If I understand correctly, you want to embedded all assemblies into one exe.
There is an amazing NuGet package called Costura.Fody. Merging assemblies could not be easier!
If you need to merge Resource DLLs, you are in luck! There is another NuGet that extends Costura.Fody called Resource.Embedder!