use*_*726 7 c# wpf smartassembly mahapps.metro
由于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和.NET 4.5的最新MahApps.Metro包.当我从Visual Studio 2012运行它时,或者当我从Debug/Release运行应用程序时,该程序可以正常工作.
以前有没有人遇到过这个问题?你是怎么解决的?问题是捆绑应用程序(SmartAssembly 6)还是MahApps.Metro?是否有任何其他捆绑程序,您知道或认为可以与MahApps.Metro一起使用?
这是我将dll放在单个exe中的方法
1)创建一个名为的文件夹DllsAsResource,并将MahApps.Metro.dlland System.Windows.Interactivity.dll和Add as Linkto 放在其中
2)Build Action将dll 更改为Embedded Resource
3)变化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();
}
}
}
Run Code Online (Sandbox Code Playgroud)
5)设置Startup object为Program.cs你的项目属性
6)现在你有一个没有发布孔dll的exe
你可以看看这个演示的所有提示
希望有所帮助
| 归档时间: |
|
| 查看次数: |
2891 次 |
| 最近记录: |