locked
Registering DLL to GAC via code? RRS feed

  • Question

  • How can I register a DLL that I´ve compiled using the 2.0 NET Framework, to the GAC?
    Is there also a way o unregister? How can this managment be done?
    Tuesday, July 24, 2007 3:03 PM

Answers

  • Mattews,

     

    It's a security risk for any other application to directly register entries into the GAC.  Only GACUTIL is given permission to do that sort of thing, which allows administrators to ban GAC registrations through the .NET Framework adminstration tools.


    But, you could try something like this:

     

    Code Snippet

        Friend Class GAC

            '/ <summary>

            '/ Add strong-named assembly to GAC. DLL must be in current directory.

            '/ </summary>

            '/ <param name="assemblyName">name of assembly (without .dll extension).</param>

     

            Friend Sub Register(ByVal assemblyName As String)

                Dim processStartInfo As ProcessStartInfo = New ProcessStartInfo("gacutil.exe", String.Format("/i {0}.dll", assemblyName))

                processStartInfo.UseShellExecute = False

                Dim process As Process = process.Start(processStartInfo)

                process.WaitForExit()

            End Sub

     

            '/ <summary>

            '/ Remove assembly from GAC.

            '/ </summary>

            '/ <param name="assemblyName">name of assembly (without .dll extension).</param>

     

            Friend Sub Unregister(ByVal assemblyName As String)

                Dim processStartInfo As ProcessStartInfo = New ProcessStartInfo("gacutil.exe", String.Format("/u {0}.dll", assemblyName))

                processStartInfo.UseShellExecute = False

                Dim process As Process = process.Start(processStartInfo)

                process.WaitForExit()

            End Sub

        End Class

     

     

    Hope that can help you.
    Friday, July 27, 2007 5:25 AM

All replies

  • Mattews,

     

    It's a security risk for any other application to directly register entries into the GAC.  Only GACUTIL is given permission to do that sort of thing, which allows administrators to ban GAC registrations through the .NET Framework adminstration tools.


    But, you could try something like this:

     

    Code Snippet

        Friend Class GAC

            '/ <summary>

            '/ Add strong-named assembly to GAC. DLL must be in current directory.

            '/ </summary>

            '/ <param name="assemblyName">name of assembly (without .dll extension).</param>

     

            Friend Sub Register(ByVal assemblyName As String)

                Dim processStartInfo As ProcessStartInfo = New ProcessStartInfo("gacutil.exe", String.Format("/i {0}.dll", assemblyName))

                processStartInfo.UseShellExecute = False

                Dim process As Process = process.Start(processStartInfo)

                process.WaitForExit()

            End Sub

     

            '/ <summary>

            '/ Remove assembly from GAC.

            '/ </summary>

            '/ <param name="assemblyName">name of assembly (without .dll extension).</param>

     

            Friend Sub Unregister(ByVal assemblyName As String)

                Dim processStartInfo As ProcessStartInfo = New ProcessStartInfo("gacutil.exe", String.Format("/u {0}.dll", assemblyName))

                processStartInfo.UseShellExecute = False

                Dim process As Process = process.Start(processStartInfo)

                process.WaitForExit()

            End Sub

        End Class

     

     

    Hope that can help you.
    Friday, July 27, 2007 5:25 AM
  • Actually, that solved my problem! Smile

    But I still need one more thing. Is there a way to check if an assembly is registered? Also, is there a way to unregister the DLL without having the dll file?

    Thanks alot! Smile
    Saturday, July 28, 2007 10:15 PM