Register DLL in GAC (CMD or PowerShell)

Viewed 24552

I'm trying to register a .DLL in the GAC. Currently I'm having trouble to prove it has been added to the assembly.

Using the command

C:\Windows\System32>%programfiles(x86)%\Microsoft SDKs\Windows\v7.0A\Bin\gacutil.exe -i "path\to\my\file.dll"

The prompt tells me that the assembly has been added to the cache.

When checking with

C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin>gacutil.exe -l file.dll

It says that there are 0 elements in the assembly.

Via Powershell commands, I'm trying to add the DLL like this:

PS C:\WINDOWS\system32> Add-Type -AssemblyName "System.EnterpriseServices"

PS C:\WINDOWS\system32> $publish = New-Object System.EnterpriseServices.Internal.Publish

PS C:\WINDOWS\system32> $publish.GacInstall("file.dll")

What did I do wrong? How can I add the .DLL to the GAC? The best way (for me) would be doing that with Powershell.

5 Answers

Use the following *.bat to install or update DLL to GAC using GacUtil.exe within the visual studio developer command prompt

@ECHO OFF
cls
ECHO ------: GAC UPDATER :-----
ECHO -                        -
ECHO  - Updating  %1
gacutil /if %1

Save this as install.bat and call it with a parameter like install abcd.dll the %1 will receive the parameter as text and will serve Gacutil as gacutil /if abcd.dll, the /if here forces to install the dll thus updating it in case it already available.

In absence of the GacUtil.exe you can use the powershell script below

Set-location (Get-Location).Path
[System.Reflection.Assembly]::Load("System.EnterpriseServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")
$publish = New-Object System.EnterpriseServices.Internal.Publish
$publish.GacInstall((Get-Location).Path + "\YourFile.dll")

This powershell script gets the current location of itself and assumes the YourFile.dll to be next to it, in case the dll is in some remote location update the script to replace $publish.GacInstall((Get-Location).Path + "\YourFile.dll") with $publish.GacInstall("path to \YourFile.dll")

Save the script as install.ps1remember to replace the YourFile.dll with your dll name and place it next to the the script file then execute the script

how to install dll in gac using powershell on Azure , using azure storage , i make 2 fils renci_dll.ps1 (this is my powershell file) and main.cmd ti call my powershell file and this is the code of my powershell file that does not works , because i have an error when i restart IR SSIS and I execute the deployed package on server Azure

Note that : in desktop i install the dll easly and packages runs successfully , the problem in cloud renci_dll.ps1 :

Set-location (Get-Location).Path [System.Reflection.Assembly]::Load("System.EnterpriseServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a") $publish = New-Object System.EnterpriseServices.Internal.Publish $publish.GacInstall((Get-Location).Path + "\Renci.SshNet.dll") enter image description here

Check the filename without the extension (.dll) C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin>gacutil.exe -l file

Related