我为此创建了新项目作为概念证明,但我无法让它发挥作用。
我创建了一个 ClassLibrary1.dll,其中包含一个简单的方法,版本为 1.0.0.0。我创建了一个调用该方法的 WindowsFormsApplication1,版本也是 1.0.0.0。我为每个解决方案创建了相关的设置项目并安装了 MSI。到目前为止一切都很好。
然后,我将 ClassLibrary1 的所有版本号增加到 1.0.1.0。我创建了一个配置文件来重定向到新版本:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="ClassLibrary1" publicKeyToken="99e3abf647b4f724" culture="neutral" />
<bindingRedirect oldVersion="1.0.0.0" newVersion="1.0.1.0"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
我用这个命令创建了一个 policy.1.0.ClassLibrary1.dll 发布者策略:
al /embed:ClassLibrary1.dll.config /out:Policy.1.0.ClassLibrary1.dll /keyfile:TestKey.snk /platform:anycpu /v:1.0.1.0
我使用安装程序将其插入 GAC,并在安装程序安装 DLL 后手动插入。两种方式的结果都是一样的:a gacutil /l policy.1.0.ClassLibrary1 返回 GAC 中策略的一个实例,但运行程序无法使用新版本。
C:\Program Files (x86)\Liberty Testing\ClassLibrary1>gacutil /l Policy.1.0.ClassLibrary1
Microsoft (R) .NET Global Assembly Cache Utility. Version 4.0.30319.0
Copyright (c) Microsoft Corporation. All rights reserved.
The Global Assembly Cache contains the following assemblies:
Policy.1.0.ClassLibrary1, Version=1.0.1.0, Culture=neutral, PublicKeyToken=99e3abf647b4f724, processorArchitecture=MSIL
Number of items = 1
不过,我会注意到手动查看 C:\Windows\Assembly 并不会显示策略程序集存在于该子树中的任何位置。我卸载了所有库并重新安装了新版本,程序现在崩溃而不是使用新的 DLL。fuslogvw 输出如下所示:
*** Assembly Binder Log Entry (6/26/2017 @ 2:31:59 PM) ***
The operation failed.
Bind result: hr = 0x80070002. The system cannot find the file specified.
Assembly manager loaded from: C:\Windows\Microsoft.NET\Framework64\v2.0.50727\mscorwks.dll
Running under executable C:\Program Files (x86)\Liberty Testing\Test Form\WindowsFormsApplication1.exe
--- A detailed error log follows.
=== Pre-bind state information ===
LOG: User = DOMAIN\user
LOG: DisplayName = ClassLibrary1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=99e3abf647b4f724
(Fully-specified)
LOG: Appbase = file:///C:/Program Files (x86)/Liberty Testing/Test Form/
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = NULL
Calling assembly : WindowsFormsApplication1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null.
===
LOG: This bind starts in default load context.
LOG: No application configuration file found.
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v2.0.50727\config\machine.config.
LOG: Post-policy reference: ClassLibrary1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=99e3abf647b4f724
LOG: The same bind was seen before, and was failed with hr = 0x80070002.
ERR: Unrecoverable error occurred during pre-download check (hr = 0x80070002).
它似乎根本没有考虑发布者政策。我们花了几天时间试图找出我们做错了什么。还有其他人有什么想法吗?