.NET 2003 deployment assembly

xiaoxiao2021-03-31  205

The four parts names of the assembly are independent of location. That is, it is independent of the name of the assembly DLL. The assembly DLL tells the public language runtime (CLR) or host applications about information about the actual assembly file location. Because the assembly DLL can deploy many different locations in a variety of different ways, this provides a valuable flexibility. This also means that the CLR must use content other than the program set to find it at runtime.

There are three main methods to deploy assemblies on the target computer. The first method involves deploying it as a private assembly by looking for DLLs in the ApplicationBase directory. The second method involves installing a DLL in a repository within a computer named a global assembly cache (GAC). The third method involves configuring the element configuration assembly DLL, which allows the CLR to download it from the network when the host application uses the DLL for the first time.

This page

Private assembly global assembly cache uses a configuration basic code deployment assembly download cache set loading summary

Private assembly

Deploying a DLL as a private assembly is the easiest way to use. If a privateBinPath property is set, the DLL can be deployed to the ApplicationBase directory of the host application or the subdirectory of the ApplicationBase directory. In most cases, it is indeed so easy.

One of the most benefits of a private assembly deployment is that it allows deployment XCopy. This is due to the application, its profile and all its private assemblies are included in a single directory structure. After the application and its private assembly are thoroughly tested, you only need to use a utility such as XCopy.exe or a network transfer protocol such as FTP, you can deploy the ApplicationBase directory structure to the target computer to deploy the entire application. You only need to deploy an application by using drag and drop functions in Windows Explorer. After copying the ApplicationBase directory structure, you can use the application (assuming the inventory of the public language).

The private assembly deployment has a payable limit, that is, it will never be deployed to the outside of the ApplicationBase directory. You cannot share private assemblies between two or more applications that are deployed to separate directorys.

So, how does the CLR find and load a private assembly? Oh, the CLR discovers the physical path at runtime through a search process called a probe. When the CLR begins to detect a private assembly, it determines the file name of the assembly by extracting the friendly name of the assembly and adds the .dll extension.

Once the CLR determines the name of the target assembly file, it first views whether there is a target assembly in the GAC, then search within the ApplicationBase directory, check whether the target assembly is in this directory. If it is in it, the probe will stop, and the CLR loads the assembly into memory. Otherwise, the detection process continues in the subdirectory of the assembly itself in the ApplicationBase directory. For example, if the CLR is probing an assembly called MyLibrary, it will look at whether it is a subdirectory named MYLIBRARY and contains an assembly file MyLibrary.dll in the ApplicationBase directory.

If the CLR finds an assembly file in the subdirectory, load the assembly. If you can't find it, the CLR will continue to detect an assembly file with the .exe extension (instead of .dll extension) in the same two directory. This means that the CLR automatically looks for four different paths when probing a private program set. If the application will have an ApplicationBase directory that will have a path to c: / myApp, the CLR will use the following four file paths to automatically detect assembly files:

C: /myapp/mylibrary.dll

C: /myapp/mylibrary/mylibrary.dll

C: /myapp/mylibrary.exec: /myapp/mylibrary/mylibrary.exe

Therefore, the CLR will automatically check the four file paths when the probe is not related to the regional assembly. When the CLR is detecting an access assembly with a regional identifier, it will also find in subdirectory as the regional identifier itself. With this additional support, it will be much easier when deploying multiple resources and localizing assemblies that are different from different languages.

Please note that although you can deploy a private assembly in any subdirectories in the ApplicationBase directory, if your name is different from the previous introduction, the CLR will need to use additional configuration information to help it detect. You must add special elements to your application configuration file to provide clues for CLR.

Let us assume that you want to create a subdirectory named myassemblies inside the ApplicationBase directory, and you want to deploy some dependence assemblies within Myassemblies. Only after you modify the application profile to include the probe element, the application can load these private assemblies, as shown below:

As you can see, element contains a privatePath property that informs to the CLR where to find it. If you want to add multiple subdirectories in a private path, you can use them through a semicolon-separated string to connect them.

It should also be remembered that the CLR checks the predetermined directory sequence during the detection process. Assuming that myassemblies is privatepath, the CLR will now probe the same as MYLIBRARY as follows:

C: /APPS/Mylibrary.dll

C: /APPS/Mylibrary/Mylibrary.dll

C: /APPS/Myassemblies/mylibrary.dll

C: /APPS/Myassemblies/mylibrary/mylibrary.dll

C: /APPS/Mylibrary.exe

C: /APPS/Mylibrary/mylibrary.exe

C: /apps/myassemblies/mylibrary.exe

C: /APPS/Myassemblies/mylibrary/mylibrary.exe

The CLR is very important in the order of the file path of the program set file, which is due to the program set file with the correct file name after the CLR finds the file, the probe will stop. If you deploy an application and a version of myLibrary.dll into the ApplicationBase directory, the other version is deployed in the Myassemblies subdirectory, then which DLL file will the CLR will load? You should find that the CLR will load DLL in the ApplicationBase directory, which is because the CLR always searches in this directory during the probe.

Back to top

Global assembly cache

You cannot use a private assembly deployment to share the assembly DLL between several applications on the same computer. For this reason, the best way is to install the assembly in the GAC.

Installing the assembly DLL in the GAC will eliminate the path-dependent problem between the application and dependent DLL. This does not affect the location of the application's applicationBase directory. As long as the assembly DLL is installed in the GAC, CLR can always find and load it. There is another significant benefit using GAC, that is, as long as you need, you can install any multiple versions of the same assembly DLL on a single computer. This is very important, because different applications can load the MYLIBRARY.DLL version that is best for them, which illustrates how the GAC will promote and travel and deploy.

The GAC design is a safe repository for the assembly. Therefore, the CLR is designed for two important limits in the GAC installed DLL. First, unless you have an Administrators or Power Users privilege on your target computer, you cannot add or remove assemblies from the GAC. Second, unless the GAC contains a strong name, you can't install the assembly in it, which is in design, when you install the assembly DLL in the GAC, the CLR will perform strong name verification for the number of the assembly. Check, ensuring that the GAC contains only those assemblies that have been signed by a user with the correct private key.

A payable interesting phenomenon is that when the CLR loads an assembly in the GAC during runtime, it does not perform a strong name verification check for the digital signature of the assembly. This is because the CLR assumes that the assembly in the GAC has been verified. Therefore, deployment assembly in the GAC slightly improves performance. If you don't want to pay a strong name verification check at runtime, you can only load the strong name from the GAC.

Now let's discuss how CLR management gac in internal management The £ CLR contains a system component called an assembly manager that is responsible for storing the assembly file in the GAC and loads them at runtime by the application when used by the application. The assembly manager is loaded from system component fusion.dll.

I must point out that the way the assembly manager stores and retrieves assembly files on the target computer should be considered a private implementation details of the CLR. I intend to describe some of these details, the purpose is to make you better understand how GAC work. The application you design or the deployment method used will never rely on these private details because they may change in the future version of the CLR.

The assembly manager uses a special directory structure in the Windows file system to store the assembly file in the GAC. The directory structure is created as subdirectory in the Windows directory, which is as follows:

C: / windows / askEMBLY / GAC

When you install the assembly to the GAC, the assembly manager creates a new directory that stores their. In fact, the assembly manager creates a unique directory for each assembly stored in the GAC. The reason for this is that the GAC must be able to accommodate two different assemblies, and the names of the two assemblies are only different from the public key value or version number. After all, there may be many files named MYLIBRARY.DLL. Therefore, the assembly manager uses all four parts of the assembly name to create a unique directory for each assembly. For example, envision you install a 1.0.24.2 version of MyLibrary.dll in the GAC, and this assembly has a public key mark 29989d7a39acf230. When you install, the assembly manager creates a new directory with the following path:

C: /Windows/assembly/gac/mylibrary/1.0.24.0__29989d7a39acf230

As you can see, the assembly manager uses its own internal naming scheme when you store the assembly to the GAC. When the assembly manager starts to load an assembly with a specific four-part name, because the assembly meets the same naming scheme, the assembly manager knows where to find it. When you want to install the assembly to the GAC, you don't need to interact directly with Fusion.dll, but use a utility that has been written for you, interacting with Fusion.dll. If you would like to install the assembly to the GAC on the development workstation for testing, you can use the Microsoft.NET Framework SDK to be available in the command line utility called Gacutil.exe. Gacutil.exe provides a number of command line switches used to install and manage assemblies in the GAC. For example, the / I switch is used for general installation of the assembly, as shown below:

Gacutil.exe / I MYLIBRARY.DLL

In order to use this method to install an assembly in the GAC, you must be able to access the assembly file. However, it is also important to note that the assembly manager creates a copy of the assembly file when installing the assembly file to the GAC. After installation, the assembly manager only cares about the copy it created. This means that after you install the initial assembly file to the GAC, you can delete it. If you set up an assembly file from the CD, you can remove the CD from the drive without any problems; if you install an assembly file from the network, you can disconnect the network connection, which will not have problems.

You can also use the GUI-based utility called the Program Cache Viewer to check and manage assemblies in the GAC, and the Program Cache Viewer is a management utility that extends as a Windows Shell extension called Shfusion.dll Transparently run in Windows Explorer. This utility is located in the / windows / assembly directory (see Figure 1).

Figure 1 Program Cache Viewer

Note that the view provided by the Program Cache Viewer does not actually display the physical layout of the directory structure maintained by the GAC. Instead, it displays a tiling view, in which all assemblies are displayed as a single scrollful list. You should also note that your friendly name, version number, regional, and public key tag are displayed for each assembly.

The Program Cache Viewer provides an easy way for administrators and developers to install and delete an assembly from the GAC. If you wish to install the assembly, you can drag and drop it from the Windows Explorer to the Program Cache Viewer. When you want to remove the assembly from the GAC, you can select it in the Program Cache Viewer and press the Delete key on the keyboard.

Keep in mind that fusion.dll is the only component that allows you to read and write files to the GAC. When you use the Program Cache Viewer management assembly, you should learn about the Windows Shell Extension SHFusion.dll interacts with Fusion.dll in the background, thereby executing the command you sent.

Back to top

Use the configuration basic code deployment assembly

The last option for deploying the assembly on the target computer is configured using the element. Configured elements is powerful because it allows you to download the assembly DLL over the network. This means that the CLR can download it to the target computer as needed for the application to use the assembly DLL.

You can deploy an assembly with a strong name in any directory on the target computer, and you can even deploy an assembly with a strong name on a file server or web server, then you can use the element in the target. The application is configured on the computer to download the assembly as needed. If you plan to use the element to deploy an assembly, you can build them with a strong name to allow this additional flexibility. Figure 2 shows an example of an application-specific element. Note that you can add elements to your Machine.config file (rather than application profile) to manage dependence assemblies within your computer.

Check the element shown in Figure 2. Note that the element must be placed in the element. In this example, the element is also available inside the element, which has some properties to identify the friendly names and public key tags of the configured concluded assembly.

Although elements only include elements, it can have many internal elements, which is a separate element due to each independent version of the assembly. The element in Figure 2 contains only one version of the element that is 1.0.24.0, but you can add other elements for other versions of the assembly.

Note that element includes an HREF attribute in addition to the version attributes. The purpose of the HREF attribute is to provide a Uniform Resource Identifier (URI) for CLR to allow it to determine the location of the assembly file. If you want to configure the assembly on the local file system on the local file system, you should use the HREF attribute similar to the following URI:

HREF = "file: /// c: /acmecorpshaedassemblies/mylibrary.dll"

If you want to configure the relying assembly to download from the file server using a unified naming point name, you should use the following URI to configure the HREF attribute:

HREF = "file: //acmecorpfileserver1/downloads/mylibrary.dll"

If you want to configure the relying assembly to download from the web server using HTTP, you should configure the HREF attribute using the following URI:

HREF = "http://www.acmecorp.com/downloads/mylibrary.dll"

Keep in mind, you can also use the .NET Framework configuration management tool mscorcfg.msc to configure the element, MSCORCFG.MSC is a Microsoft Management Console (MMC) management unit, which can be from the Windows "Start" menu The shortcut in the Management Tools group started. Thus, there is no need to directly process the XML in the application configuration file or the Machine.config file. By the way, when you start configuring an application and its relying on assembly, you must know the Microsoft .NET Framework configuration management tool is a GUI-based convenient tool. Figure 3 shows the UI of the utility.

Figure 3 .NET Framework configuration .NET Framework configuration management tool is convenient because it can create an application configuration file for you. You only need to configure an application by interacting with a standard Windows control (such as text box, radio button, and check box). When you configure an application in this way, Microsoft .NET Framework Configuration Management Tool performs the creation of appropriate XML content and adds it to these cumbersome work in the application configuration file.

Back to top

Download cache

Now let's discuss what happens when the CLR's assembly manager uses the element, and downloads the relying on the program set through the network. The assembly manager does not directly load the assembly file into the memory that is running, in contrast, the assembly manager downloads the assembly file and writes it to the temporary storage area named download cache.

This cache scheme has a significant advantage. There is no need to copy the assembly file multiple times through the network. The assembly file only needs to be downloaded and saved to the disk when the application is first used. The assembly manager can load an assembly file from the download cache on the local hard drive.

There are two important differences between download caches and GAC. The GAC is indeed a repository within the computer, and the download cache is not. The download cache is actually managed by the CLR based on each user. For example, if a user named Bob runs an application, the application uses the element to download the assembly file via the network, then the assembly manager stores the assembly file in the private child directory of the user. In the following path:

C: / Documents and Settings / Bob / Local Settings / Application Data /

Another important difference is that because the GAC is local, the assembly manager treats it as a fully trusted secure repository of the assembly. Download the cache is not too safe and not fully trusted. Therefore, the assembly manager will be considered from the download cache load as a mobile code that is subject to other security restrictions. Be sure to know this because the CLR runs the mobile code in a restricted sandbox, prevent the host from being attacked.

Back to top

Jack

Now, it is possible to discuss the situation when the assembly manager needs to load the dependency assembly into the running application. The assembly manager first splits the format stroke into the four parts of the assembly it wants to find. Typically, the assembly manager determines the format string by looking for references in the list of another assembly.

Let us look at an example. Imagine you run myApp.exe, and it performs the first line of code that requires the CLR to load Mylibrary.dll. The assembly manager checks myApp.exe list list and discovers the four parts name of the MYLIBRARY.DLL of the program set file, which already has Mylibrary.dll when compiling the application used. If MYLIBRARY.DLL has a strong name, the assembly manager generates a format string containing the public key tag, as shown below:

MYLIBRARY,

Version = 1.0.24.0,

Culture = neutral,

PublickeyToken = 29989D7A39ACF230

At this point, the assembly manager has four parts names of the dependent assembly that already exist during compiling myApp.exe. In the next step, the assembly manager views whether there is any configuration information to redirect the application so that it uses another version number. Let us assume that in this discussion, the version number will not be redirected.

After the assembly manager knows the four parts of the assembly it wants to find, you can start searching for assembly files now. The assembly manager executes its search as follows. First, it checks the redirect position of the configuration file (such as ) and search the assembly in the GAC. Next, it uses the configuration information search assembly in the element. Finally, it searchs for assemblies by performing probing in the ApplicationBase directory. The assembly manager always has important meanings in the GAC. Imagine what happens if you deploy three copies of the same assembly. For example, envision that you have placed a copy of the assembly DLL in the ApplicationBase directory, deploy the second copy using the element and install the third copy to the GAC. The assembly manager will always load an assembly from the GAC. Once it finds an assembly in the GAC, you will stop searching.

If the assembly manager finds the configured element and finds one, it will then look at whether the URI points to the location on the local hard disk. If you point out, the assembly manager loads an assembly file directly from the location of the disk.

If the URI in the element points to an assembly file on another computer, the assembly manager knows that it can only download the local copy of the assembly file from the download cache. Therefore, the assembly manager checks the download cache to see if the assembly file has been downloaded. If not downloaded, the assembly manager will copy it from the network to the download cache. When the assembly file is downloaded to the download cache, the assembly manager will load it.

If the assembly manager can't find an assembly file in the GAC, and it discovers that the assembly is not configured element, it detects the ApplicationBase directory. The assembly manager performs the probe process by following the following method: Find directly in the ApplicationBase directory, and then find it in each subdirectory in accordance with the rules previously introduced in the chapter of the private assembly.

As you can think, there will be many problems when the CLR tries to load the assembly. For example, if the assembly manager detects an assembly file when you probe in the ApplicationBase directory, it will cause FileNotFoundException to a row code, which causes the assembly manager to look up the assembly. The CLR will trigger filenotfound anomalies in the following situations: When it can't find the assembly file configured in the element, and when it determines that the app loaded is not the correct version number, regional settings, or public key value Time.

Back to top

summary

This month, I introduced three main methods used to deploy an assembly DLL. Private assembly deployment is valuable because it provides all the advantages of XCopy deployment. But it also has some limitations because you must deploy assembly DLL to the ApplicationBase directory structure. Deploy assembly in the GAC is very useful because it allows you to share assembly DLLs between several different applications, and are independent of the location of each application's ApplicationBase directory. The GAC also provides the benefits of assemblies as a fully trusted security repository. Finally, if you deploy an assembly DLL using an element, you will allow you to deploy a strong name to any location or any accessible location on your local hard drive. There are two main benefits to use elements. First, you are not limited to deploy assembly DLL to the ApplicationBase directory structure. Second, you can configure the assembly DLL to be downloaded from the network by the CLR.

转载请注明原文地址:https://www.9cbs.com/read-130953.html

New Post(0)