zoukankan      html  css  js  c++  java
  • Getting a copy of a DLL in the GAC

    Getting a copy of a DLL in the GAC

    A few weeks ago, Patrick Wellink blogged about how you would get a copy of a DLL when it's in the GAC. Today I had the same problem but after reading Patrick's blog post and the comments, I decided to write a small console application to make that process somewhat easier.

    This application takes at least two arguments. The first argument is the physical path to the GAC on the system. The second is the path where the DLL needs to be copied. The following example copies all Crystal components in the GAC to a backup folder:

    GetGACAssemblies C:\Windows\Assembly C:\Projects\GACBackup Crystal*.dll

    If you just need a backup of all GAC assemblies, simply do something like this:

    GetGACAssemblies C:\Windows\Assembly C:\Projects\GACBackup

    To build the application, I used the ScanDirectory class I blogged about earlier. The code for this console application is really simple:

    using System;
    using System.IO;
     
    namespace GetGACAssemblies
    {
        class Program
        {
            private static string _targetPath;
     
            static void Main(string[] args)
            {
                // You need at least two arguments
                if (args.Length >= 2)
                {
                    // Get the target path and make sure it exists
                    _targetPath = args[1];
                    if (!_targetPath.EndsWith(@"\"))
                    {
                        _targetPath += @"\";
                    }
     
                    if (!Directory.Exists(_targetPath))
                    {
                        Directory.CreateDirectory(_targetPath);
                    }
     
                    // Setup the directory scanner object
                    ScanDirectory scanner = new ScanDirectory();
     
                    scanner.FileEvent += new ScanDirectory.FileEventHandler(scanner_FileEvent);
                    if (args.Length == 2)
                    {
                        scanner.SearchPattern = "*.dll";
                    }
                    else
                    {
                        scanner.SearchPattern = args[2];
                    }
     
                    // Start the scan
                    scanner.WalkDirectory(args[0]);
                }
            }
     
            static void scanner_FileEvent(object sender, FileEventArgs e)
            {
                string newFile = _targetPath + e.Info.Name;
     
                if (File.Exists(newFile))
                {
                    File.Delete(newFile);
                }
                File.Copy(e.Info.FullName, newFile);
            }
        }
    }

    You can download the code for the console application here.

    Getting a copy of a DLL that's only in the GAC

    Ok probably there is a simpeler way of doing this but i googled for it and couldn't find it. So here is the story.

    I needed a specific DLL that was placed in the GAC by the install of BizTalk. I needed the DLL cause I needed to ad a reference in my C# project. If anybody knows how to add a Reference to a DLL tha's in the GAC I'll be interested as well.

    But I couldn't find a way to do it so I needed a copy of that dll.

    So you use explorer and Browse to the GAC.

    WindowsGac.JPG

    But you can't make a copy of it, You can see all the details and stuff but you cannot copy it. But if you open a Command prompt and go to the same directory stuff looks different....

    CommandGac.JPG

    And for sure when you go to the correct directory you can get the underlying DLL.

    CommandGac1.JPG

    There are probably easier ways of doing this but I thought I share this method of doing it.

  • 相关阅读:
    Linux Enterprise Cluster NOtes Ch4 同步:ssh和rsync
    e805上不安装中文外挂支持中文,很简单而且实用
    ARM的一些概念性问题
    C#调用WORD处理的小项目 转
    ASP.NET面试题
    .net清除cookie代码|.net为什么不能清除cookie|.net cookie 过期代码
    c#字符串转数字的函数|c#字符串转数字的无错函数|c#字符串转数字的最好函数
    Wiki简介
    new 和override 重写区别
    禁用IE的后退按钮|显示网页已过期|几种语言的实现方法|c#|javascript|html
  • 原文地址:https://www.cnblogs.com/snowball/p/863788.html
Copyright © 2011-2022 走看看