7

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

这个结论是在创建一个只有 MahApps.Metro 的完全空的项目时得出的,并且仍然无法捆绑它。

它抛出带有内部异常的异常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 的最新 MahApps.Metro 包和 .NET 4.5。当我从 Visual Studio 2012 运行该程序或从 Debug/Release 运行应用程序时,该程序可以工作。

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

4

1 回答 1

8

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

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

2)Build Action将dll更改为Embedded Resource

3)更改Copy Localfalse正常引用的dll

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 objectProgram.cs你的项目属性中设置

6)现在你有一个没有发布洞 dll 的 exe

您可以查看此演示以获取所有提示

希望有帮助

于 2014-03-01T19:38:46.450 回答