Using PowerShell to Install a DLL into the GAC

A couple of ways exist to install a DLL into the Global Assembly Cache (GAC). Using gacutil.exe is one, but this comes as part of a Visual Studio installation, and in a server environment, you may not have the luxury of installing Visual Studio, just to get the utility installed.

An alternative, however, is to use PowerShell to install the DLL into the GAC. The following code snippet should take care of your needs.

  • kiran gowda

    I am getting below errors .

    Exception calling “Load” with “1” argument(s): “Could not load file or assembly ‘System.EnterpriseServices,
    Version=, Culture=neutral, PublicKeyToken=7f48c3199e5dff41’ or one of its dependencies. The system cannot fi
    the file specified.”
    At C:UsersAdministratorDesktoptest.ps1:1 char:1
    + [System.Reflection.Assembly]::Load(“System.EnterpriseServices, Version=, …
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : FileNotFoundException

    New-Object : Cannot find type [System.EnterpriseServices.Internal.Publish]: verify that the assembly containing thi
    type is loaded.
    At C:UsersAdministratorDesktoptest.ps1:2 char:12
    + $publish = New-Object System.EnterpriseServices.Internal.Publish
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidType: (:) [New-Object], PSArgumentException
    + FullyQualifiedErrorId : TypeNotFound,Microsoft.PowerShell.Commands.NewObjectCommand

    You cannot call a method on a null-valued expression.
    At C:UsersAdministratorDesktoptest.ps1:3 char:1
    + $publish.GacInstall(“ctccs.dll”)
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

    • Exception shows you trying to load “System.EnterpriseServices, Version=”, but the tutorial above calls for “System.EnterpriseServices, Version=”. Can you confirm your code?

  • Rick Brown

    If we already have .net 4.6.1 how do we install System,EnterpriseServices?

  • lcgillies

    Thanks, great alternative to hours of trying to get VS to install cleanly!

  • nhlanhla mbanjwa

    Hi..does this solution also register dll on Component Service?

    I have com+ dll that i need to register on a client machine.

    Any help will be appreciated