Serious trouble with ILMerge and .NET 4.0

前端 未结 5 609
误落风尘
误落风尘 2020-12-28 22:41

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

相关标签:
5条回答
  • 2020-12-28 22:56

    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.

    0 讨论(0)
  • 2020-12-28 23:05

    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.

    AppDomain.CurrentDomain.AssemblyResolve += (sender, args) => {
    
       String resourceName = "AssemblyLoadingAndReflection." +
    
          new AssemblyName(args.Name).Name + ".dll";
    
       using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName)) {
    
          Byte[] assemblyData = new Byte[stream.Length];
    
          stream.Read(assemblyData, 0, assemblyData.Length);
    
          return Assembly.Load(assemblyData);
    
       }
    
    };
    

    see: http://blogs.msdn.com/b/microsoft_press/archive/2010/02/03/jeffrey-richter-excerpt-2-from-clr-via-c-third-edition.aspx

    0 讨论(0)
  • 2020-12-28 23:06

    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.

    0 讨论(0)
  • 2020-12-28 23:07

    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.

    0 讨论(0)
  • 2020-12-28 23:22

    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

    0 讨论(0)
提交回复
热议问题