[英]Installing RSAT for Windows 8.1 does not place expected assemblies in the GAC
[英]Installing and uninstalling assemblies in GAC with WindowsPowerShell
在Windows Server 2012計算機上,一個msi文件已將程序集ABCD.dll安裝到GAC_32中。 我嘗試使用以下命令使用WindowsPowerShell修補此文件:
[System.Reflection.Assembly]::Load("System.EnterpriseServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")
$publish = New-Object System.EnterpriseServices.Internal.Publish
$publish.GacRemove("C:\Windows\Microsoft.NET\assembly\GAC_32\ABCD\v4.0_1.0.0.0__8a93b7fd09f0e7e7\ABCD.dll")
$publish.GacInstall("C:\Patch1\ABCD.dll")
但是,GacRemove命令失敗。 在Windows事件日志/應用程序中,我收到以下消息:
從全局程序集緩存中刪除程序集失敗:C:\\ Windows \\ Microsoft.NET \\ assembly \\ GAC_32 \\ ABCD \\ v4.0_1.0.0.0__8a93b7fd09f0e7e7 \\ ABCD.dll ABCD,Version = 1.0.0.0
有人有想法嗎,可能是什么原因?
我也嘗試了32位(C:\\ Windows \\ SysWOW64 \\ WindowsPowerShell \\ v1.0 \\ powershell.exe)和64位(C:\\ Windows \\ System32 \\ WindowsPowerShell \\ v1.0 \\ powershell.exe)WindowsPowershell管理員模式。
gacutil也不起作用。 我嘗試以下方法:
"C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin\NETFX 4.0 Tools\gacutil" -u ABCD.dll
並得到以下消息:
Microsoft (R) .NET Global Assembly Cache Utility. Version 4.0.30319.1
Copyright (c) Microsoft Corporation. All rights reserved.
No assemblies found matching: ABCD.dll
Number of assemblies uninstalled = 0
Number of failures = 0
但是當我得到的程序集列表
"C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin\NETFX 4.0 Tools\gacutil" -l
我看到以下行:
ABCD, Version=1.0.0.0, Culture=neutral, PublicKeyToken=8a93b7fd09f0e7e7, processorArchitecture=x86
如文章“ Microsoft Installer不會從GAC中刪除程序集-全局程序集緩存針”一樣 ,問題是HKEY_CLASSES_ROOT \\ Installer \\ Assemblies \\ Global \\ [程序集全名]中的注冊表項具有已設置的值,當該組件由msi安裝時。 因此,要修補程序集,必須清除注冊表值,必須卸載程序集,必須安裝修補后的程序集,並且注冊表值必須設置為舊值。 注冊表值可以保留為空,但是在卸載msi時,不會刪除注冊表項。 因此,最好將注冊表值再次設置為舊值。 我終於寫了以下VB.NET代碼來修補程序集:
Dim subkey = My.Computer.Registry.ClassesRoot.OpenSubKey("Installer\Assemblies\Global", True)
Dim keyname = "ABCD,Version=""1.0.0.0"",Culture=""neutral"",ProcessorArchitecture=""MSIL"",PublicKeyToken=""8A93B7FD09F0E7E7"""
Dim values As String() = subkey.GetValue(keyname)
subkey.SetValue(keyname, {""})
Dim assemblyname =
"C:\Windows\Microsoft.NET\assembly\GAC_32\ABCD\v4.0_1.0.0.0__8a93b7fd09f0e7e7\ABCD.dll"
Dim p = New System.EnterpriseServices.Internal.Publish()
p.GacRemove(assemblyname)
p.GacInstall("D:\Patch1\ABCD.dll")
subkey.SetValue(keyname, values)
在上面的代碼中,必須將ABCD更改為正確的程序集名稱,並將8a93b7fd09f0e7e7更改為程序集的公鑰令牌。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.