[英]How to set ProgressBarForeground in MahApps.Metro ProgressDialog?
[英]How to bundle MahApps.Metro into single exe
由于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.
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.dll
和System.Windows.Interactivity.dll
与Add 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)现在你有一个没有发布孔dll的exe
你可以看看这个演示的所有提示
希望有所帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.