WWW Yariv Hammer's Code Site

Wednesday, February 15, 2006

Placing Assemblies in the Global Assembly Cache (GAC)

This article is one of a series of articles exploring .NET Assemblies.
Exploring .NET Assemblies
Multi-File Assemblies
Strong Named Assemblies
Placing Assemblies in the Global Assembly Cache (GAC)
Administrative Configuration of Applications
The articles are intended for programmers who are using .NET for a while, and wish to know more about .NET assemblies.

The Global Assembly Cache (GAC) is a repository of .NET assemblies. Assemblies which are stored in the GAC are meant to be shared by several applications on the computer. Good examples of such assemblies are the .NET Framework assemblies (System.Data.dll, System.Xml.dll, etc).

In .NET the deployment process is called XCopy deployment: you just copy the output folder from one place to another and everything works without the need to register stuff on the computer. The Registry is avoided altogether in .NET, and in future Windows versions, it might disappear.

As default, when you reference a dll, and build the project, VS.NET will copy the dll to the output folder, where the exe is generated (Unless the Copy Local property of the reference is set to false). You can place the dll in a sub folder named as the dll without problem. If the referenced Assembly is in the GAC, it will appear in the .NET tab of the Add Reference dialog in .NET, and the Copy Local property will be set to false as default. The exe will know to look for the assembly in the GAC.
There is a very good article about where the assembly searches the referenced assemblies here:

Placing an Assembly in the GAC
There are few ways to place an assembly in the GAC. First of all you must sign the assembly with a strong name (look here).
One way is to simply copy the assembly file to the GAC folder: C:\WINDOWS\assembly (this is relevant to my computer), by dragging using Windows Explorer.
As you can see this is not a regular folder: You can see that many assemblies appear several times with different versions (the public key token can also be seen). This is the solution to "Dll Hell". Dlls can exist side-by-side with different versions. This way old application which has reference to the old versions can still work.

Another way is to use the command line utility: gacutil /i MyAssembly.dll.

The last way is to use the administrative tools for .NET. Open Start->Control Panel->Administrative Tools->.NET Configuration 1.1 .
On the dialog select "Assembly Cache", and then click on "Add an Assembly to the Assembly Cache". Select the assembly and it will be added to the GAC. If you click on "View List of Assemblies in the Assembly Cache", you can see a different view of the GAC, and you can delete an assembly from the GAC (be careful). You can also delete the assembly from the windows folder.

Setting the Version of the Assembly
In order to version the assembly, you should open the AssemblyInfo file in the project and set the AssemblyVersion attribute. [assembly: AssemblyVersion("1.0.*")].
The version consists of four number separated by dots ([major version].[minor version].[build number].[revision]). The asterisk (*) tells the framework to advance the two least significant numbers every build. The two most significant numbers (the left ones) should be changed by you when you want to change versions. This version can be seen in the Manifest of the assembly, and can be seen as a result in the GAC.
You can set some attributes (AssemblyTitle, AssemblyDescription, etc...) to characterize the assembly. This attributes can be seen in Windows Explorer by right-clicking on the assembly file, selecting "Properties", in the Version tab.

In order to change the version of the dll that the exe should refer to (for example if I now have a new dll, and the old exe is still referring to the old version of the dll), we need to change the application configuration file of the exe. This file must be located in the same folder as the exe, and the name of the file is [exename].exe.config . If there is no such file, you can add it yourself. The following code must appear in the file:
<bindingRedirect oldVersion="" newVersion=""/>
For more information you can look here: or in the link I have posted in the introduction.

Note: You can configure an application assembly through the administrative tool .NET Configuration 1.1 (in Control Panel) by adding an assembly to the Applications section. The tool will generate the App.Config for you.


At 2:44 AM, June 27, 2017, Blogger kingrani said...

Flipkart is Offering Cashback Offers Flipkart SBI Cashback Offer You will get upto 75% Discount

Flipkart is Offering Cashback Offers Flipkart AXIS Cashback Offer You will get upto 75% Discount

Flipkart is Offering Cashback Offers Flipkart YES Cashback Offer You will get upto 75% Discount

Flipkart is Offering Cashback Offers Flipkart Phonepe Cashback Offer You will get upto 75% Discount

Flipkart is one of the biggest world wide eCommerce Site flipkart cashback offersso

Flipkart is one of the biggest world wide eCommerce Site Flipkart hdfc offersso


Post a Comment

<< Home

Feel free to use everything here. Add links to my site if you wish.

Do not copy anything to other sites without adding link to here.

All the contents of the site belong to Yariv Hammer.