Friday, May 23, 2014

Install and uninstall assemblies from GAC

Its easy to install and uninstall a bunch of dlls thru the powershell scripts 

install.ps1
set-alias -name Gacutil -value "C:\Program Files (x86)\Microsoft SDKs\Windows\v8.0A\bin\NETFX 4.0 Tools\gacutil.exe"
get-childitem | where {$_.extension -eq ".dll"}| Foreach-Object {Gacutil /i $_}

uninstall.ps1
set-alias -name Gacutil -value "C:\Program Files (x86)\Microsoft SDKs\Windows\v8.0A\bin\NETFX 4.0 Tools\gacutil.exe"
get-childitem | where {$_.extension -eq ".dll"}| Foreach-Object {Gacutil /u $_.BaseName}

Steps to test
1. Create folder, then create 2 ps1 files by pasting the code written above
2. Copy the dlls  that need to be deployed to GAC into that folder
3. Open Windows Powershell
4. Navidate to that folder by executing  cd <folder path>
5. Optionally run the command to allow ps1 to run from the prompt  Set-ExecutionPolicy Unrestricted
6. To install all the dlls of that folder run ./install.ps1
7. To install all the dlls of that folder run ./uninstall.ps1

Note: the value given for Gacutil will be different depending on the framework installed in your box. You may have to change it accordingly.