June 9, 2009

Gac Assemblies in Powershell

I first came across this on a post in StackOverflow about a month ago. The question was how to add assemblies to the Gac from a text file. Here is a (very) slightly modified solution from what I saw there:
sal -Name gacutil -Value $env:ProgramFiles'\Microsoft SDKs\Windows\V6.0A\bin\gacutil.exe'
filter gac-item { gacutil /nologo /i $_}
gc c:\list.txt | ?{$_ -like "*.dll"} | gac-item
The text file 'list.txt' would basically contain assemblies and their paths like:
C:\ICSharpCode.SharpZipLib.dll
c:\MyFile.dll
C:\MyAssemblyLocations\MyAssemblies\Test.dll
I was curious how easy it would be to just point to a folder and take all .dll files as opposed to looking at a text document. You can do that by modding the above script with this:
sl -Path $env:ProgramFiles\'MyBigProject\Bin'

foreach ($file in gci -Filter "*.dll" ) {
gacutil /nologo /i $file.Name
}
Powershell really makes things like this very simple.

2 comments:

  1. Hi Joe;
    Thanks for the post. But this means that you have to distribute GacUtil.exe with your software. I am just a little uncertain about licensing side of the deal... aren't you?

    Thanks
    Nasser.

    ReplyDelete
  2. Hi Nasser:

    Yes and no. Gacutil is installed with anyone who has installed .NET framework...so it should be there. Also, used this for updating environments, so I knew where it was..not sure how you were thinking of using it?

    Thanks!
    Joe

    ReplyDelete