Click here to Skip to main content
Click here to Skip to main content
Go to top

Installing a DLL into the Global Assembly Cache (GAC)

, 30 Apr 2013
Rate this:
Please Sign up or sign in to vote.
How to add a DLL to the GAC

Introduction 

This article provides a simple explanation of how to install a DLL into the Global Assembley Cache (GAC). 

There are several reasons you might want to do this: 

Sharing and Versioning the Assembly

The assembly may be used by more than one application and more than one version of the assembly may be required. Multiple versions can sit side-by-side in the GAC. 

Security 

The GAC is held in the system root so is likely to be more secure out-the-box. You also don't have to secure it multiple places. 

Assembly Searching

The GAC is checked after the local folder and before probing and checking the codebase information. 

Getting Started 

Create a strong name key pair:

Firstly we need to create a strong name key file. This will be in the format: sn –k <filename and location>. An example is shown below. This creates a file containing a public\private key pair.  

Sign the assembly via Visual Studio

Signing the assembly is very easy - you could do it the hard way using an assembly linker but why would you? Right click on the project and go to properties. Select the signing tab then select the ‘sign the assembly’ check box. Point to the key pair file you created above. In this example I have copied the key file into the bin\debug folder and I am using it to sign a ReportingUtilities DLL which is generated in the same folder. 

Installing into the GAC

Now that we have a signed assembly we can install it into the GAC. Run the Visual Studio command prompt (in visual studio tools) and write the following instruction in the format: gacutil –I <assembly name >. In this example I have changed the cmd prompt directory to the location of the DLL - you can do this or put the full assembly path in the assembly name.      

Install into the GAC via an MSI

In a production environment the reality is that you won’t have visual studio installed.

Not to worry. To install a DLL into the GAC is still quite easy - you just need to create a deployment project.

In Visual Studio add a deployment project to your visual studio solution.

  • Choose a standard set up program – not wizard.
  • Right click on the project, select view, file system
  • Right click on the File System on target machine and select GAC

  • Right click on the generated GAC folder and select the primary output from the DLL project as shown below. Make sure you select the correct project from the drop down!

The project will also add a launch condition for the .NET framework. Make sure this version is set to the version that is going to be on the target machine as it will default to the latest version on your development machine (which might be greater).

To change this version:  

  • Right click on the project and select launch conditions
  • In the launch conditions select the .Net Framework
  • Click the properties tab. You may need to reselect the launch condition to highlight the correct properties. It should look like so:

You can now build your project and copy the files to the environment where you need to install the DLL. 

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

GraemeKMiller
Architect http://www.uiguy.co.uk
United Kingdom United Kingdom
I am an enterprise application developer with around 8 years .Net experience.
 
I am currently focusing on Silverlight, WCF and SQL Server.

Comments and Discussions

 
QuestionInstalling in wrong gac PinmemberPetros Orloff26-Jun-14 5:13 
QuestionNice oNe PinmemberBrijesh Kr25-Nov-13 5:20 
GeneralMy vote of 5 PinmemberAbuOmar7-Oct-13 9:06 
Questionuse MSI Pinmvpadriancs30-Apr-13 23:36 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web03 | 2.8.140926.1 | Last Updated 30 Apr 2013
Article Copyright 2013 by GraemeKMiller
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid