惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

N
Netflix TechBlog - Medium
T
The Blog of Author Tim Ferriss
aimingoo的专栏
aimingoo的专栏
A
About on SuperTechFans
Stack Overflow Blog
Stack Overflow Blog
B
Blog RSS Feed
Microsoft Security Blog
Microsoft Security Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
人人都是产品经理
人人都是产品经理
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
J
Java Code Geeks
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
B
Blog
MongoDB | Blog
MongoDB | Blog
L
LangChain Blog
WordPress大学
WordPress大学
小众软件
小众软件
IT之家
IT之家
腾讯CDC
月光博客
月光博客
量子位
Blog — PlanetScale
Blog — PlanetScale
P
Proofpoint News Feed
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More

博客园 - 阿冠

git报错unable to read tree xxxxxx socket tcp 报错误码 103/10053 原因 NuGet 未能为 SSL/TLS 安全通道建立信任关系 NuGet 未能为 SSL/TLS 安全通道建立信任关系 Visual Studio Font Cache 字体缓存路径下的文件太大了 ControlTemplate 中 Bingding 附加属性时需要加入 Path WPF使用第三方的字体(TTF文件) Base class for cloning an object in C# 关闭Windows 系统当前连接的Wifi以及判断物理\虚拟网卡,有线\无线网卡 - 阿冠 - 博客园 WPF 竖排文字 WPF 程序自删除(自毁)|卸载程序删除 WPF listbox UI虚拟化 记一次纠结Macbook 重装OS X的系统 指定的元素已经是另一个元素的逻辑子元素。请先将其断开连接。(解决问题总结) 无法将类型为“System.Windows.Controls.SelectedItemCollection”的对象强制转换为类型“System.Collections.Generic.IList`1 foreach---集合已修改;可能无法执行枚举操作。 WPF_View中控件使用单例ViewModel 判断s2是否能够被通过s1做循环移位(rotate)得到的字符串是否包含 多列转1列 SqlServer 实现oracle10g的 wmsys.wm_concat()--for xml path('')
WPF 将DLL嵌入EXE文件(安装包)
阿冠 · 2016-05-26 · via 博客园 - 阿冠

网上很多例子,各种套路,就是没有测试过。

WPF 将DLL嵌入EXE文件的套路是这样的

1.将要引用的dll源文件添加到wpf 项目中,dll 的属性-》生成操作为【嵌入的资源】。

2.监听    AppDomain.CurrentDomain.AssemblyResolve 事件

监听的事件的位置很重要,跟wpf 的运行顺序有关系吧。

找到wpf 项目中的App.xaml 文件,App.xaml.cs 类的构造函数中监听。

1   public App()
2         {
3            
4             CatchException();
5             AppDomain.CurrentDomain.AssemblyResolve += OnResolveAssembly;
6         }

 1  private static Assembly OnResolveAssembly(object sender, ResolveEventArgs args)
 2         {
 3             var requestedAssemblyName = new AssemblyName(args.Name);
 4             string resourceName = "当前项目的命名空间" + "." + requestedAssemblyName.Name + ".dll";
 5             System.Windows.Forms.MessageBox.Show(resourceName);
 6             try
 7             {
 8                 using (System.IO.Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName))
 9                 {
10                     byte[] buffer = new byte[stream.Length];
11                     stream.Read(buffer, 0, buffer.Length);
12                     return Assembly.Load(buffer);
13                 }  
14             }
15             catch (Exception ex)
16             {
17                 System.Windows.Forms.MessageBox.Show(String.Format(@"{0}\{1}",ex.Message,ex.StackTrace));
18                 throw;
19             }
20         }

View Code

参考了一下链接

http://www.codeproject.com/Articles/310675/AppDomain-AssemblyResolve-Event-Tips

http://www.digitallycreated.net/Blog/61/combining-multiple-assemblies-into-a-single-exe-for-a-wpf-application

http://www.cnblogs.com/luoshupeng/p/3951597.html

http://www.cnblogs.com/xiashengwang/archive/2012/07/16/2593921.html