Click here to Skip to main content
15,886,101 members
Articles / Operating Systems / Windows

Extract GAC Assemblies

Rate me:
Please Sign up or sign in to vote.
4.45/5 (14 votes)
6 Jan 2007CPOL2 min read 66.6K   852   22  
Extracts .NET assemblies from GAC
#region Copyright notice
// ==================================================================================================
// This is an as-is implementation. feel free to use this code anyway you like :)
//
//                                                                     - Moim Hossain
//                                                                       2006
// ==================================================================================================
#endregion

#region Using Directives
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
#endregion

namespace GACExplorer
{
    /// <summary>
    /// Encapsulates an assembly informations inside this class
    /// </summary>
    public class AssemblyInformation
    {
        string name;
        string version;
        string culture;
        string publicKeyToken;
        FileInfo fInfo;

        /// <summary>
        /// Creates a new instance
        /// </summary>
        /// <param name="fInfo"></param>
        public AssemblyInformation(FileInfo fInfo)
        {
            this.fInfo = fInfo;
            UpdateInformation();
        }

        /// <summary>
        /// Get or set the name
        /// </summary>
        public string Name
        {
            get { return name; }
            set { name = value; }
        }

        /// <summary>
        /// Get or set the version
        /// </summary>
        public string Version
        {
            get { return version; }
            set { version = value; }
        }

        /// <summary>
        /// Get or set the culture
        /// </summary>
        public string Culture
        {
            get { return culture; }
            set { culture = value; }
        }

        /// <summary>
        /// Get or set the 
        /// </summary>
        public string PublicKeyToken
        {
            get { return publicKeyToken; }
            set { publicKeyToken = value; }
        }

        /// <summary>
        /// Get the full name
        /// </summary>
        public string FullName
        {
            get { return string.Format("{0}, Version={1}, Culture=natural, PublicKeyToken={2}", name, version, publicKeyToken); }
        }

        /// <summary>
        /// Get the file informations
        /// </summary>
        public FileInfo FileInformation
        {
            get { return fInfo; }
        }

        /// <summary>
        /// Update the informations
        /// </summary>
        private void UpdateInformation()
        {
            string name = fInfo.Name.Substring(0, fInfo.Name.LastIndexOf("."));
            string version = string.Empty;
            string publicKeyToken = string.Empty;
            try
            {
                string directory = fInfo.DirectoryName.Substring(fInfo.DirectoryName.LastIndexOf("\\") + 1);
                version = directory.Substring(0, directory.IndexOf("__"));
                publicKeyToken = directory.Substring(directory.IndexOf("__") + 2);
            }
            catch (Exception)
            {
            }

            this.name = name;
            this.version = version;
            this.publicKeyToken = publicKeyToken;
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

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


Written By
Architect
Netherlands Netherlands
Engineer Powered by the Cloud

Comments and Discussions