前言
我們在很大的項目開發,會發現項目引用的 dll 會很多,我想要按照不同的功能,將不同的 dll 放在不同的文件夾
簡單的方法是通過修改 App.config 文件指定文件夾,如將文件移動到 abc\12 的文件夾里面,可以在 App.config 添加代碼
1
2
3
4
5
6
7
8
|
<? xml version = "1.0" encoding = "utf-8" ?> < configuration > < runtime > < assemblyBinding xmlns = "urn:schemas-microsoft-com:asm.v1" > < probing privatePath = "abc\12" /> </ assemblyBinding > </ runtime > </ configuration > |
如創建一個簡單的項目,此時項目引用一個dll 如 doubi.dll 這個項目運行的時候輸出的文件有 lindexi.exe 和 doubi.dll 文件
這時需要將 doubi.dll 移動到文件夾 abc\12 里面
1
2
|
lindexi.exe abc\12\doubi.dll |
打開 App.config 添加上面的代碼就可以
如果有兩個不同的dll需要放在兩個不同的文件夾,如 walter.dll 需要放在 walter 文件夾
在 <probing privatePath="abc\12" />
里面使用分號表示不同的文件夾 probing privatePath="abc\12;walter"
不同的文件夾之間用分號分開
1
2
3
4
5
6
7
8
|
<? xml version = "1.0" encoding = "utf-8" ?> < configuration > < runtime > < assemblyBinding xmlns = "urn:schemas-microsoft-com:asm.v1" > < probing privatePath = "abc\12;walter" /> </ assemblyBinding > </ runtime > </ configuration > |
這個 App.config 在編譯之后會在被修改為 程序集名.exe.config 在輸出文件夾找到 xx.exe.config 可以通過修改這個文件在編譯之后修改 dll 的尋找文件夾
如果是對于 C++ 的 dll 需要做特殊引用,如需要區分 x86 和 x64 請看C# 如何在項目引用x86 x64的非托管代碼
不能直接添加一個 x86 文件和一個 x64 文件夾,通過 privatePath 同時指定文件夾的方式
總結
以上就是這篇文章的全部內容了,希望本文的內容對大家的學習或者工作具有一定的參考學習價值,如果有疑問大家可以留言交流,謝謝大家對服務器之家的支持。
原文鏈接:https://lindexi.gitee.io/lindexi/post/C-通過-probing-指定-dll-尋找文件夾.html