Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

C # how to put the dll in the specified folder

2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces the relevant knowledge of "C# how to put dll in the designated folder". The editor shows you the operation process through an actual case. The method of operation is simple and fast, and it is practical. I hope this article "how to put dll in the designated folder" can help you solve the problem.

C # client program, generated is an exe, if there is a lot of dll, then dll and exe will be confused together, look very chaotic, we can set up a folder, put dll into it, so it looks very clear and beautiful.

There are two ways.

The first is the configuration method.

1. Let's set up a winform program, refer to the two dll separately, and call the methods in it.

The generated file looks like this

two。 Open the App.config folder, where dll and dll/2 are equivalent to folders

3. Select all dll and set replication locally to FALSE

4. Open the exe path of the project, create a dll folder, and put one of the dll in it.

Create a dll/2 folder and put another dll in it

5. The effect of folders

WindowsFormsApp4.exe

WindowsFormsApp4WindowsFormsApp4.exe.config

Dll

. / ClassLibrary1.dll

. / 2/ClassLibrary2.dll

6. The effect, it looks better this way.

Second, the code method

1. Also set up a project, select all dll, and set the replication locally to FALSE

two。 Write at the initialization of the form

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. In the debug folder of the project, create the name dll2 folder in the code and throw all the dll into it.

4. Code

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 ()) } / static System.Reflection.Assembly CurrentDomain_AssemblyResolve (object sender, ResolveEventArgs args) {string path = System.IO.Path.Combine (AppDomain.CurrentDomain.BaseDirectory, @ "dll2\") is called when external parsing of dll fails. Path = System.IO.Path.Combine (path, args.Name.Split (',') [0]); path = String.Format (@ "{0} .dll", path); return System.Reflection.Assembly.LoadFrom (path);} about "how to put dll in the designated folder", thank you for reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report