2013-11-01 21 views
4

我有我的WPF应用程序的这样的输出文件的数量:如何将文件合并到单一的可执行文件或减少分布式文件

de\ 
es\ 
fr\ 
hu\ 
it\ 
pt-BR\ 
Resources\ 
ro\ 
ru\ 
sv\ 
zh-Hans\ 
FileHelpers.dll 
FileHelpers.DataLink.dll 
FileHelpers.ExcelStorage.dll 
Interop.Excel.dll 
Interop.Office.dll 
Ionic.Zip.dll 
wpftoolkit.dll 
Xceed.Wpf.AvalonDock.dll 
Xceed.Wpf.AvalonDock.Themes.Aero.dll 
Xceed.Wpf.AvalonDock.Themes.Metro.dll 
Xceed.Wpf.AvalonDock.Themes.VS2010.dll 
Xceed.Wpf.DataGrid.dll 
Xceed.Wpf.Toolkit.dll 
MyApp.Common.Extensions.dll 
MyApp.Common.Helpers.dll 
MyApp.Common.Types.Attributes.dll 
MyApp.Security.dll 
MyApp.Wpf.Controls.dll 
MyApp.exe 
MyApp.exe.config 
licence.key 
error.log 

一切从MyApp开始由自己开发的,一切由3dParty 我做想分发我的应用程序,但为了做到这一点,我想合并一切可能的事情来分发文件的最小数量。

我试图用ilmerge合并到单一的一个我的文件,但得到了一个错误:比我是读ilmerge limitationsassembly as resources by Jeffrey Richter

ILMerge.Merge: ERROR!!: Duplicate type 'XamlGeneratedNamespace.GeneratedInternal TypeHelper' found in assembly 'Xceed.Wpf.DataGrid'. 对这个问题,我在这里找到xeed error reason 答案

所以我发现Jeffrey Richter解决方案非常有用。但我不能将它应用于我的程序,因为程序集上没有“生成操作”属性。

为了实现我的目标,我能做些什么吗?

enter image description here

+0

出于好奇,为什么要最小化文件数量?这似乎不是一个非常有效率的使用你的时间.. –

+0

@Miky Dinescu他他,你可能是对的,但我想明白为什么杰弗里的想法不适合我。 – sreginogemoh

回答

2

看看展鹏的SmartAssembly。

+0

嘿,我会尝试一下,但我仍然想知道为什么Jeffry的方法不适用于我的情况。 – sreginogemoh

7

为了让杰弗里的想法工作,您应该添加您的程序集不仅作为参考。只需将dll添加为项目(右键单击项目 - >添加 - >现有项目)到您的项目中,您将获得构建操作属性。同时设置将本地属性复制为false对于您添加为嵌入资源的引用。

enter image description here

应用类的构造函数:

public partial class App : Application 
{ 
    public App() 
    { 
     AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve; 
    } 
    static Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args) 
    { 
     var dllName = new AssemblyName(args.Name).Name + ".dll"; 
     var execAsm = Assembly.GetExecutingAssembly(); 
     var resourceName = execAsm.GetManifestResourceNames().FirstOrDefault(s => s.EndsWith(dllName)); 
     if (resourceName == null) return null; 
     using (var stream = execAsm.GetManifestResourceStream(resourceName)) 
     { 
      var assbebmlyBytes = new byte[stream.Length]; 
      stream.Read(assbebmlyBytes, 0, assbebmlyBytes.Length); 
      return Assembly.Load(assbebmlyBytes); 
     } 

    } 
} 

注重,这种方法消耗比平时加载DLL更多的内存。

+0

太好了,也会使用'RedGate的SmartAssembly'作为@gap建议 – sreginogemoh

+0

这会如何影响引用的程序集列表参考文件夹?这会影响编译时间或运行时间吗?我真的很想检查这一点,不知道这一切是如何工作的? – IbrarMumtaz

+0

在正常情况下,您必须具有所有程序集的引用,以向编译器提供有关类型的所有必需信息。您将Copy local设置为false,因为在运行时从资源加载的所有程序集(不在GAC中)。当CLR第一次遇到来自这个Dll的类型并调用JIT编译时会发生这种情况。因此,您不能直接在Main()中使用这些类型。 – Deffiss

相关问题