none
How to copy dll file in windows\assembly folder? RRS feed

  • Question

  • How to copy dll file in windows\assembly folder?

    i have created a dll file in vb.net 2005 and now i want to add in c:\WINDOWS\assembly through coding or using command how to do it?

    manually i can darg n drop dll in assembly but how to do it from code or command

    Thanks in Advance

    Please Help Its Urgent!!

    Thursday, March 10, 2011 4:37 PM

Answers

  • Hello krunal90,

     

    1. >> see basically i want to execute from code in vb.net...so is der any way to do it ??

    1.1 Yes there is a way to do it.

    1.2 Section 2 below provides a brief outline of how this can be done.

    1.3 Section 3 below provides a recommended method for you using source codes provided from a blog (link provided in section 4).

    1.4 Section 4 below provides useful links which you would be interested in. Source codes are provided in these links.

     

    2. Brief Outline of How to Install/Uninstall Assemblies To/From the GAC via Source Code.

    2.1 You need to use the IAssemblyCache interface to perform this.

    2.2 This interface is actually a COM interface. An implementation of this interface is provided by the .NET framework.

    2.3 To access this interface implementation, you need to PInvoke into the CreateAssemblyCache() API exported by Fusion.dll, e.g. :

            [DllImport("fusion.dll")]
            static extern int CreateAssemblyCache
            (
              out IAssemblyCache ppAsmCache,
              int reserved
            );

    Note however, that the IAssemblyCache interface is a COM interface which means that it is not defined in any system provided namespaces (including the System.Runtime.InteropServices.ComTypes namespace). Hence it needs to be manually defined in source codes. Fortunately some very nice developers have already done this for us and links to their websites are provided in section 4 below.

    2.4 After pinvoking the CreateAssemblyCache() API and obtaining a pointer to an IAssemblyCache COM interface, use the IAssemblyCache::InstallAssembly() and IAssemblyCache::UninstallAssembly() methods to install/uninstall assemblies.

    2.5 There are also other very cool IAssemblyCache methods, e.g. QueryAssemblyInfo() and other COM interfaces, e.g. IAssemblyName, that you may like to explore.

     

    3. Recommendation For You.

    3.1 Use the source codes provided by Junfeng Zhang from his blog "Sample Managed GAC API Wrappers" (http://blogs.msdn.com/b/junfeng/archive/2004/09/14/229649.aspx).

    3.2 Junfeng provided several very good wrapper classes for the IAssemblyCache and other interfaces exported from fusion.dll. The one which we are currently interested in is the AssemblyCache class.

    3.3 I recommend that you make a copy of the entire GACWrap.cs source provided by Junfeng and then compile a class library from it (e.g. GACWrap.dll).

    3.4 Thereafter, create your VB.net application and reference GACWrap.dll. In your VB source codes, import the System.GACManagedAccess namespace.

    3.5 The following is a sample VB.net code that makes use of Junfeng's AssemblyCache class :

        Sub InstallToGAC()
            Dim assemblyPath As String
            Dim id As String
            Dim Data As String
            Dim flags As AssemblyCommitFlags
            Dim reference As InstallReference

            '' Best practice is to provide a proper full path to the assembly
            '' that is to be installed to the GAC.
            assemblyPath = "TestAssembly01.dll"
            id = "krunal90"
            Data = "krunal90"

            reference = New InstallReference(InstallReferenceGuid.OpaqueGuid, id, Data)
            flags = AssemblyCommitFlags.Default

            AssemblyCache.InstallAssembly(assemblyPath, reference, flags)
        End Sub


    3.6 For simplicity, I suggest that you use the InstallReferenceGuid.OpaqueGuid for creating an InstallReference class instance and provide simple strings for "id" and "Data" (e.g. "krunal90").

    3.7 Note that if you need to uninstall the same assembly from the GAC, the same InstallReferenceGuid and "id" and "Data" values must be used. Also recommended when you uninstall an assembly is to use a fully qualified name to specify the assembly, e.g. "name, Version=xx, Culture=xx, PublicKeyToken=xx, ProcessorArchitecture=xx". See Junfeng's comments for the AssemblyCache.UninstallAssembly() method for more details.

    3.8 The following is a sample subroutine that uninstalls the same assembly from the GAC :

        Sub UninstallFromGAC()
            Dim assemblyPath As String
            Dim id As String
            Dim Data As String
            Dim reference As InstallReference

            assemblyPath = "TestAssembly01, Version=1.0.0.0, Culture=Neutral, PublicKeyToken=7a618bbd4adfb8f6, ProcessorArchitecture=x86"
            id = "krunal90"
            Data = "krunal90"

            reference = New InstallReference(InstallReferenceGuid.OpaqueGuid, id, Data)

            Dim disp As AssemblyCacheUninstallDisposition

            AssemblyCache.UninstallAssembly(assemblyPath, reference, disp)
        End Sub
     

    4. Useful Links

    4.1 "Sample Managed GAC API Wrappers" by Junfeng Zhang.

    http://blogs.msdn.com/b/junfeng/archive/2004/09/14/229649.aspx

    4.2 "Install Assembly in GAC with C#" by Mauricio Rojas

    http://blogs.artinsoft.net/mrojas/archive/2008/04/09/install-assembly-in-gac-with-c.aspx

    4.3 ".NET Fusion" by Richard Grimes

    http://www.grimes.demon.co.uk/workshops/fusWSTen.htm

     

    - Bio.

     

    • Proposed as answer by Paul Zhou Monday, March 14, 2011 2:17 AM
    • Marked as answer by Paul Zhou Friday, March 18, 2011 1:52 AM
    Sunday, March 13, 2011 7:04 AM

All replies

  • you can use gacutil, more info here:

    http://msdn.microsoft.com/en-us/library/ex0ss12c(v=VS.100).aspx

    HTH,

    Patrick

    Thursday, March 10, 2011 4:56 PM
  • Thanks for reply

    sorry but 'gacutil' is not recognized as an internal or external command,
    operable program or batch file.

    Thursday, March 10, 2011 5:32 PM
  • Hello krunal89,

    You need to run gacutil from a Visual Studio Command Prompt. See http://msdn.microsoft.com/en-us/library/ms229859.aspx.

    - Bio.

     

    Thursday, March 10, 2011 5:39 PM
  • Thanks for reply

    ok then how to run from normal cmd pls help

    Thursday, March 10, 2011 5:45 PM
  • Hi krunal89,

     

    Welcome to the MSDN forum!

     

    It may be difficult to run from normal cmd.

    You have to do it in Visual Studio Command Prompt using the command:

    gacutil [options] [assemblyName | assemblyPath | assemblyListFile]

     


    Paul Zhou [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Friday, March 11, 2011 8:58 AM
  • Thanks for reply

    see basically i want to execute from code in vb.net

    so is der any way to do it ??

    Friday, March 11, 2011 9:54 AM
  • Hello krunal90,

     

    1. >> see basically i want to execute from code in vb.net...so is der any way to do it ??

    1.1 Yes there is a way to do it.

    1.2 Section 2 below provides a brief outline of how this can be done.

    1.3 Section 3 below provides a recommended method for you using source codes provided from a blog (link provided in section 4).

    1.4 Section 4 below provides useful links which you would be interested in. Source codes are provided in these links.

     

    2. Brief Outline of How to Install/Uninstall Assemblies To/From the GAC via Source Code.

    2.1 You need to use the IAssemblyCache interface to perform this.

    2.2 This interface is actually a COM interface. An implementation of this interface is provided by the .NET framework.

    2.3 To access this interface implementation, you need to PInvoke into the CreateAssemblyCache() API exported by Fusion.dll, e.g. :

            [DllImport("fusion.dll")]
            static extern int CreateAssemblyCache
            (
              out IAssemblyCache ppAsmCache,
              int reserved
            );

    Note however, that the IAssemblyCache interface is a COM interface which means that it is not defined in any system provided namespaces (including the System.Runtime.InteropServices.ComTypes namespace). Hence it needs to be manually defined in source codes. Fortunately some very nice developers have already done this for us and links to their websites are provided in section 4 below.

    2.4 After pinvoking the CreateAssemblyCache() API and obtaining a pointer to an IAssemblyCache COM interface, use the IAssemblyCache::InstallAssembly() and IAssemblyCache::UninstallAssembly() methods to install/uninstall assemblies.

    2.5 There are also other very cool IAssemblyCache methods, e.g. QueryAssemblyInfo() and other COM interfaces, e.g. IAssemblyName, that you may like to explore.

     

    3. Recommendation For You.

    3.1 Use the source codes provided by Junfeng Zhang from his blog "Sample Managed GAC API Wrappers" (http://blogs.msdn.com/b/junfeng/archive/2004/09/14/229649.aspx).

    3.2 Junfeng provided several very good wrapper classes for the IAssemblyCache and other interfaces exported from fusion.dll. The one which we are currently interested in is the AssemblyCache class.

    3.3 I recommend that you make a copy of the entire GACWrap.cs source provided by Junfeng and then compile a class library from it (e.g. GACWrap.dll).

    3.4 Thereafter, create your VB.net application and reference GACWrap.dll. In your VB source codes, import the System.GACManagedAccess namespace.

    3.5 The following is a sample VB.net code that makes use of Junfeng's AssemblyCache class :

        Sub InstallToGAC()
            Dim assemblyPath As String
            Dim id As String
            Dim Data As String
            Dim flags As AssemblyCommitFlags
            Dim reference As InstallReference

            '' Best practice is to provide a proper full path to the assembly
            '' that is to be installed to the GAC.
            assemblyPath = "TestAssembly01.dll"
            id = "krunal90"
            Data = "krunal90"

            reference = New InstallReference(InstallReferenceGuid.OpaqueGuid, id, Data)
            flags = AssemblyCommitFlags.Default

            AssemblyCache.InstallAssembly(assemblyPath, reference, flags)
        End Sub


    3.6 For simplicity, I suggest that you use the InstallReferenceGuid.OpaqueGuid for creating an InstallReference class instance and provide simple strings for "id" and "Data" (e.g. "krunal90").

    3.7 Note that if you need to uninstall the same assembly from the GAC, the same InstallReferenceGuid and "id" and "Data" values must be used. Also recommended when you uninstall an assembly is to use a fully qualified name to specify the assembly, e.g. "name, Version=xx, Culture=xx, PublicKeyToken=xx, ProcessorArchitecture=xx". See Junfeng's comments for the AssemblyCache.UninstallAssembly() method for more details.

    3.8 The following is a sample subroutine that uninstalls the same assembly from the GAC :

        Sub UninstallFromGAC()
            Dim assemblyPath As String
            Dim id As String
            Dim Data As String
            Dim reference As InstallReference

            assemblyPath = "TestAssembly01, Version=1.0.0.0, Culture=Neutral, PublicKeyToken=7a618bbd4adfb8f6, ProcessorArchitecture=x86"
            id = "krunal90"
            Data = "krunal90"

            reference = New InstallReference(InstallReferenceGuid.OpaqueGuid, id, Data)

            Dim disp As AssemblyCacheUninstallDisposition

            AssemblyCache.UninstallAssembly(assemblyPath, reference, disp)
        End Sub
     

    4. Useful Links

    4.1 "Sample Managed GAC API Wrappers" by Junfeng Zhang.

    http://blogs.msdn.com/b/junfeng/archive/2004/09/14/229649.aspx

    4.2 "Install Assembly in GAC with C#" by Mauricio Rojas

    http://blogs.artinsoft.net/mrojas/archive/2008/04/09/install-assembly-in-gac-with-c.aspx

    4.3 ".NET Fusion" by Richard Grimes

    http://www.grimes.demon.co.uk/workshops/fusWSTen.htm

     

    - Bio.

     

    • Proposed as answer by Paul Zhou Monday, March 14, 2011 2:17 AM
    • Marked as answer by Paul Zhou Friday, March 18, 2011 1:52 AM
    Sunday, March 13, 2011 7:04 AM
  • after dll registration in add reference we cannot find my dll in .net and com tab.
    Thursday, March 31, 2011 11:24 AM