Click here to Skip to main content
Click here to Skip to main content

GAC Installer

, 14 Mar 2008
Rate this:
Please Sign up or sign in to vote.
A command line GAC installer that removes assemblies even if they are installed by an MSI.

Introduction

The Gacutil application is the most common tool for installing/uninstalling items to/from the Global Assembly Cache. However, it has some problems:

  1. The application is not distributed with the .NET framework.
  2. Inability to uninstall the assembly if it is installed by an MSI installer.
  3. Difficult to use if you uninstall the assembly and do not know the fully qualified assembly name (including the PublicToken).

An attempt to uninstall the assembly installed by an MSI will generate an error message like the one below:

D:\temp\aa>gacutil /u "MySDKDll, Version=1.0.0.0, 
Culture=neutral, PublicKey Token=da66bde628dcedb8, 
processorArchitecture=MSIL" 
Microsoft (R) .NET Global Assembly Cache Utility. Version 2.0.50727.42 
Copyright (c) Microsoft Corporation. All rights reserved. Assembly: MySDKDll, 
Version=1.0.0.0, Culture=neutral, PublicKeyToken=da66bde 628dcedb8, 
processorArchitecture=MSIL 
Unable to uninstall: assembly is required 
by one or more applications Pending references: 
SCHEME: <windows_installer />ID: <msi />DESCRIPTION : <windows installer="" />
Number of assemblies uninstalled = 0 
Number of failures = 0

There are utilities that can do the job, like GacView, but it is not command-line driven, and therefore can not be used as a part of the installer (apart from licensing issues).

The presented utility can be controlled from a command line. It removes the assemblies even if they are installed by a MSI. In order to remove such an assembly, Registry entries have to be cleared:

LocalMachine\Software\Microsoft\Installer\Assemblies\Global
   CurrentUser\Software\Microsoft\Installer\Assemblies\Global

The utility identifies the entries in these keys and removes the content.

private void ClearRegKey(string AssemblyShortName, RegistryKey BaseKey) 
{ 
    RegistryKey key = BaseKey.OpenSubKey(@"Software\Microsoft\" + 
                                         @"Installer\Assemblies\Global", true); 
    
    if (key != null) 
    { 
        string[] names = key.GetValueNames(); 
        foreach (string Name in names) 
        { 
            string[] Words = Name.Split(&#39;,&#39;); 
            string nn = Words[0]; 
            string nn2 = Words[4]; 
            if (AssemblyShortName == nn) 
            { 
                key.SetValue(Name, "", RegistryValueKind.String); key.Close(); 
            }
            return; 
        } 
    }
}

How to use the utility

Examples:

  • Installing the assembly:
  • GacInstaller.exe i "C:/Program Files/ABCD/MySDKDll.DLL"
  • Uninstalling the assembly:
  • GacInstaller.exe u MySDKDll - just the name
    GacInstaller.exe u MySDKDll da66bde628dcedb8 - using name and public token

If installation/uninstallation is unsuccessful, the application form turns red and the error information is written to the log file.

Credits

The utility uses the GAC API wrapper created by Junfeng Zhang. The original wrapper code is available here.

Version

The current version is 1.0.0. The most recent version can be downloaded from www.dotnetremoting.com along with other useful components.

License

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

About the Author

Alex_1
Web Developer
Australia Australia
No Biography provided

Comments and Discussions

 
QuestionNice article but a question PinmemberMushq14-Mar-08 1:38 
GeneralRe: Nice article but a question PinmemberAlex_114-Mar-08 11:51 

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
Web02 | 2.8.140709.1 | Last Updated 14 Mar 2008
Article Copyright 2008 by Alex_1
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid