简体   繁体   English

如何通过 PublicKeyToken 从 GAC 大量卸载程序集?

[英]How can you do a mass unload of Assemblies from GAC by PublicKeyToken?

Is there anyway to unload all assemblies from the GAC that have a specific PublicKeyToken?无论如何要从具有特定 PublicKeyToken 的 GAC 中卸载所有程序集?

I am okay with the solution being command-line (gacutil.exe, etc) or via C#.我可以通过命令行(gacutil.exe 等)或通过 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.仅供参考,我可以通过 Windows Explorer 执行此操作,然后转到程序集文件夹并按公钥排序,他们 select 所有有问题的,然后右键单击并说卸载。 If this is the only way then fine please confirm, otherwise alternatives that could be "automated" would be nice.如果这是唯一的方法,那么请确认,否则可以“自动化”的替代方案会很好。 Thanks.谢谢。

With the commandline and a little C# it's easy:使用命令行和一点 C# 很容易:

GacUtil /l  

Lists all assemblies on CSV lines.列出 CSV 行上的所有程序集。
Filter this on the keytoken and feed the names to a removelist.txt for在 keytoken 上过滤它并将名称提供给removelist.txt以获取

GacUtil /ul removelist.txt

If you like Powershell you could use something like this:如果你喜欢Powershell你可以使用这样的东西:

& '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]
    }
  }

You could use the GAC API to code your own tool.您可以使用GAC API来编写您自己的工具。 Here is a managed version of the API.是 API 的托管版本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM