2

Is there anyway to unload all assemblies from the GAC that have a specific PublicKeyToken?

I am okay with the solution being command-line (gacutil.exe, etc) or via C#.

EDIT:

FYI, I can do this via Windows Explorer and going to the assembly folder and sort by public key and they select all the ones in question and right click and say uninstall. If this is the only way then fine please confirm, otherwise alternatives that could be "automated" would be nice. Thanks.

starblue
  • 55,348
  • 14
  • 97
  • 151
Rodney S. Foley
  • 10,190
  • 12
  • 48
  • 66

3 Answers3

3

With the commandline and a little C# it's easy:

GacUtil /l  

Lists all assemblies on CSV lines.
Filter this on the keytoken and feed the names to a removelist.txt for

GacUtil /ul removelist.txt
H H
  • 263,252
  • 30
  • 330
  • 514
  • Yeah I guess I can do that, it still requires some manual effort, would love to know if there is anything better, this is still not easily to automate. – Rodney S. Foley Jun 06 '11 at 20:35
  • Maybe Powershell has tricks for this, other website. But I would call this reasonably automated. – H H Jun 06 '11 at 20:41
1

If you like Powershell you could use something like this:

& 'C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin\gacutil.exe' /L | 
  where { $_ -match '^  ([\w\.]+,.*)$' } |
  foreach {
    if ($matches[1].contains("PublicKeyToken=d7e1d90e83a016b1")) {
      & 'C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin\gacutil.exe' /u $matches[1]
    }
  }
Jan-Peter Vos
  • 3,157
  • 1
  • 18
  • 21
0

You could use the GAC API to code your own tool. Here is a managed version of the API.

Lars Truijens
  • 42,837
  • 6
  • 126
  • 143