Visual C # generate DLL files-prerequisites
A dll (Dynamic Link Library) file is an executable file that allowsProgramSharedCodeAnd other resources. In most cases, the dll extension (or. ocx file: ActiveX control file ,. cpl file: control panel file ,. DRV files: device driver files), providing code, data, or functions to programs running in windows.
Some benefits of using DLL:
Use fewer resources;
Promote modular architecture;
Simplify deployment and installation.
A dll is not a program that runs independently. It is a part of a program and can only be called by the program to which it belongs. You cannot open it.
Visual C # generate a DLL file
VisualC, Delphi, and VBProgramming LanguageAfter compilation, the generated DLL file is a binary file that can be directly used by the computer. However, although the managed code generated using the Visual C # compiler is also a binary file, it is not the original code that can be directly used by computers. It is essentially an intermediate language (IL) code, it must be compiled by the real-time Compiler (JIT) of "Next Generation window service" (ngws.
The DLL file generated with Visual C # is essentially different from the previous DLL file. The DLL files generated using Visual C # Are more represented by a class or class library in programming ).
Visual C # generate a DLL file-create a component
1. First create a new class library project file
File-> New-> Project-> Visual C # projects-> class library. Enter the project file name and select the directory where the file is to be stored.
2. engineering documents
Rename class1.cs as the file name to be created: mydll. CS and enter the code.
3. Generate the DLL file
Compile the project file CSC/Target: Library/out: mydll. DLL mydll. CS generation component mydll. DLL, which is located in the bin \ DEBUG directory of the project file. The file extension is DLL.
Visual C # generate DLL file -- Test DLL
1. Create a new control application
File-> New-> Project-> Visual C # projects-> console application. Use this control application to test our components.
2. Add reference for namespace
Project-> Add reference, browse to the generated DLL, and then press OK. The class that will be referenced to the current project file.
3. Call the mydll namespace, create a mydll object, and call its methods and properties.
(1) Use namespace: Using mydll;
(2) create a mydll object;
(3) Call methods and attributes.
Use the CSC command to compile the. CS file into. dll
Most of the time, we need to compile the. CS file separately into A. dll file. The operations are as follows:
Open the command window-> Enter cmd to the console-> Cd C: \ WINDOWS \ Microsoft. NET \ framework \ v1.1.4322
Go to the directory where vs.net is installed and execute the CSC command CSC/Target: library file. CS-> Generate a corresponding name under this directory. DLL file (premise: Put. put the CS file in C: \ WINDOWS \ Microsoft. net \ framework \ v1.1.4322 directory)
CSC commands are used in many ways. For more information, see the following.
Translate file. CS to generate file.exe
CSC file. CS compile file. CS to generate file. dll
CSC/Target: library file. CS compile file. CS and create my.exe
CSC/out: my.exe file. CS compiles all C # files in the current directory by optimizing and defining the debug symbol. Output as file2.exe
CSC/define: Debug/optimize/out: file2.exe *. CS compile all the C # files in the current directory to generate the debug version of file2.dll. No logo or warning is displayed
CSC/Target: Library/out: file2.dll/warn: 0/nologo/debug *. CS compile all the C # files in the current directory as something. XYZ (a DLL)
CSC/Target: Library/out: Something. XYZ *. CS compile file. CS to generate file. dll
CSC/Target: library file. CS is the most widely used command. In fact, it can be simply written as CSC/T: library file. CS. Another method is CSC/out: mycodebehind. dll/T: Library mycodebehind. CS. You can specify the output file name.
CSC/out: mycodebehind. dll/T: Library mycodebehind. CS mycodebehind2.cs. This function is to install two Cs files into A. dll file.