Register all dll in a directory in GAC Silently in powershell

11,976

Solution 1

I am the author of PowerShell GAC. With PowerShell GAC you don't need gacutil and you can install all dlls in a folder to the GAC with the following command.

# Can only be run from an elevated prompt
Add-GacAssembly C:\Folder\*.dll

Solution 2

Use gacutil.exe.

& gacutil.exe -i <strongly named DLL>

Note - the DLL must meet the requirements of being installable into the GAC.

Solution 3

The .Net Framework already contains methods to register components in the GAC. No need to add SDKs and third party plugins.

[System.Reflection.Assembly]::Load("System.EnterpriseServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")
$publisher = New-Object System.EnterpriseServices.Internal.Publish

# For installation 
$publisher.GacInstall("C:\Components\MyComponent.dll")

# For removal
$publisher.GacRemove("C:\Components\MyComponent.dll")
Share:
11,976
user1595214
Author by

user1595214

Updated on June 08, 2022

Comments

  • user1595214
    user1595214 about 2 years

    I have to register all .dll files in a directory to GAC silently without any screen popup. How can i do this using powershell. Please help :)

  • user1595214
    user1595214 about 11 years
    what is strongly named dll.I am able to install it when clicking on install button from gacutil window,but using above command
  • Keith Hill
    Keith Hill about 11 years
    FYI the & is unnecessary. gacutil.exe will be parsed as a command and not a string.
  • Keith Hill
    Keith Hill about 11 years
    @user1595214 <strongly named dll> is just a placeholder for the path of the assembly you want to put in the GAC.
  • Andy Arismendi
    Andy Arismendi about 11 years
    @KeithHill only not necessary if running it from its current directory. Most instances I see have spaces in its path e.g. C:\Program Files\Microsoft SDKs\Windows\v7.0A\bin\gacutil.exe so to call it say the root of C you'd need & "C:\Program Files\Microsoft SDKs\Windows\v7.0A\bin\gacutil.exe". I just usually also just use it because it works in all scenarios.
  • Keith Hill
    Keith Hill about 11 years
    I guess I usually have my PowerShell configured with the SDK bin dir in my path. So I just exeucte gacutil -i .... PSCX has a very handy Import-VisualStudioVars function that will configure your PowerShell environment for various flavors of Visual Studio.
  • user1595214
    user1595214 about 11 years
    @KeithHill : hi keith,just to confirm a few things as i dont have much idea about Gacutil,Actually i am able to register dll in Gacutil if i am launching gacutil.exe and dragging dropping dll over the interface,so does it mean that all those dlls are strongly signed.And if they are strongly signed,why not i am able to do the same through command line.
  • Nick
    Nick about 11 years
    Maybe you have not run powershell specifically as an administrator?