網站首頁 編程語言 正文
C#客戶端程序,生成后是一個exe,如果帶有大量的dll,那么dll和exe會混亂在一起,看起來非常混亂,我們可以建立一個文件夾,把dll放進去,這樣看起來就非常的清晰美觀。
一共有二種方法
第一種,配置方法。
1.我們建立一個winform程序,對2個dll分別引用,調用里面的方法
生成后的文件是這樣的
2.打開App.config文件夾,其中dll和dll/2相當于文件夾
<?xml version="1.0" encoding="utf-8" ?> <configuration> <startup> <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8" /> </startup> <runtime> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <!--<publisherPolicy apply="yes" />這句不要也是可以的--> <probing privatePath="dll;dll/2" /> </assemblyBinding> </runtime> </configuration>
3.選擇所有的dll,把復制本地設置成 FALSE
4.打開項目的exe路徑,分別建立dll文件夾,把其中一個dll放進去?
建立dll/2文件夾,把另一個dll放進去
5.文件夾的效果
WindowsFormsApp4.exe
WindowsFormsApp4WindowsFormsApp4.exe.config
dll
...../ClassLibrary1.dll
...../2/ClassLibrary2.dll
6.效果,這樣就比較好看一些。
第二種,代碼方法
?1.同樣建立一個項目,選擇所有的dll,把復制本地設置成 FALSE
2.在窗體的初始化出寫入
AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;
static System.Reflection.Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
{
string path = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"dll2\");
path = System.IO.Path.Combine(path, args.Name.Split(',')[0]);
path = String.Format(@"{0}.dll", path);
return System.Reflection.Assembly.LoadFrom(path);
}
3.在項目的debug文件夾中,建立代碼中的名字dll2文件夾,把所有的dll扔進去即可。
?4.代碼
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApp1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;
}
private void Form1_Load(object sender, EventArgs e)
{
ClassLibrary1.Class1 c = new ClassLibrary1.Class1();
ClassLibrary2.Class1 c1 = new ClassLibrary2.Class1();
MessageBox.Show(c.A() + c1.B());
}
/// <summary>
/// 對外解析dll失敗時調用
/// </summary>
/// <param name="sender"></param>
/// <param name="args"></param>
/// <returns></returns>
static System.Reflection.Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
{
string path = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"dll2\");
path = System.IO.Path.Combine(path, args.Name.Split(',')[0]);
path = String.Format(@"{0}.dll", path);
return System.Reflection.Assembly.LoadFrom(path);
}
}
}
原文鏈接:https://blog.csdn.net/u012563853/article/details/124803478
相關推薦
- 2022-03-23 深入淺析OpenCV?copyTo()函數_C 語言
- 2022-10-23 C#中的yield關鍵字詳解_C#教程
- 2023-04-01 一文帶你深入了解Python中的二次移動平均法_python
- 2022-09-15 關于PCL出現"無法找到?pcl_commond.dll?文件程序無法執(zhí)行"的問題及解決方法_C 語
- 2022-04-10 Android中Protobuf的基本使用介紹_Android
- 2022-11-17 C++中的函數返回值問題_C 語言
- 2021-04-13 手動清理 Memcached 緩存的方法
- 2022-12-27 Golang中int,?int8,?int16,?int32,?int64和uint區(qū)別淺析_Gol
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環(huán)境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區(qū)別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發(fā)現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態(tài)字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支