views:

241

answers:

3

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??

+3  A: 

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.

Simon P Stevens
I don't believe there are actually any WPF resources in that assembly, but I'm not completely sure (will check when I get home). My main executable certainly does, but that doesn't appear to be the problem. Still I will look into this further. Thanks for the reply.
chaiguy
+1  A: 

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.

chaiguy
Good info. Thanks for the feedback.
Simon P Stevens
As a commercial user of .NET Reactor, I have to mention that I always failed to merge assemblies. It seemed to have merged successfully, but when you run the merged application, you will meet strange activities.
Ying
It seemed to work great when I stuck *just* to embedding (not merging), and no fancy security stuff at all. I did a runthrough of my program and everything seemed intact.
chaiguy
+1  A: 

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.

Stephen Cleary
Cool... can't wait to try this out.
chaiguy