如何将MahApps.Metro捆绑到单个exe中

由于MahApps.Metro,我很难将使用SmartAssembly 6(评估/试用版)将我的C#WPF项目中的所有依赖项捆绑到单个exe中。

这个结论是在创建一个除了MahApps.Metro之外什么都没有的完全空项目时得出的,但仍然无法捆绑它。

它会引发内部exception的exceptionSystem.IO.FileNotFoundException: Could not load file or assembly 'System.Windows.Interactivity, Version=4.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified. System.IO.FileNotFoundException: Could not load file or assembly 'System.Windows.Interactivity, Version=4.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.

我花了一天半的时间试图解决这个问题,谷歌搜索错误,尝试我能找到的每一个建议,然后发布官方MahApps.Metro聊天( https://gitter.im/MahApps/MahApps.Metro )。 我尝试了各种各样的变化,我删除了System.Windows.Interactivity dll,添加它,将它移动到另一个路径等。

使用NuGet和.NET 4.5的最新MahApps.Metro包。 当我从Visual Studio 2012运行它时,或者当我从Debug / Release运行应用程序时,该程序可以正常工作。

以前有没有人遇到过这个问题? 你是怎么解决的? 问题是捆绑应用程序(SmartAssembly 6)还是MahApps.Metro? 是否有任何其他捆绑程序,您知道或认为可以与MahApps.Metro一起使用?

这是我将dll放在单个exe中的方法

1)创建一个名为DllsAsResource的文件夹,并将MahApps.Metro.dllSystem.Windows.Interactivity.dllAdd as Link放在一起

2)将dll的Build Action更改为Embedded Resource

3)将正常引用的dll的Copy Local更改为false

4)创建Program.cs

 using System; using System.Reflection; namespace MahApps.Metro.Simple.Demo { public class Program { [STAThread] public static void Main() { AppDomain.CurrentDomain.AssemblyResolve += (sender, args) => { var resourceName = Assembly.GetExecutingAssembly().GetName().Name + ".DllsAsResource." + new AssemblyName(args.Name).Name + ".dll"; using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName)) { if (stream != null) { var assemblyData = new Byte[stream.Length]; stream.Read(assemblyData, 0, assemblyData.Length); return Assembly.Load(assemblyData); } } return null; }; App.Main(); } } } 

5)将Startup object设置为项目属性中的Program.cs

6)现在你有一个单独的exe没有发布孔dll

你可以看看这个演示的所有提示

希望有所帮助