gacutil和环境中的次要版本差异导致严重的麻烦

Cur*_*sHx 4 .net c# version global-assembly-cache c#-2.0

情况如下:

我有在.NET 2中编译的DLL,该DLL在全局程序集缓存中。我有这样的myDLL.dll.config文件:

<configuration>
   <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="myDLL" publicKeyToken="c426c33bab532523" />
        <bindingRedirect oldVersion="1.2.2.0-1.2.2.22" newVersion="1.2.2.23" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>
Run Code Online (Sandbox Code Playgroud)

然后,我使用程序集链接器创建策略文件:

al /link:myDLL.dll.config /out:policy.1.2.myDLL.dll /keyfile:myDLL.snk
Run Code Online (Sandbox Code Playgroud)

但是当我尝试使用以下方式将策略文件加载到全局程序集缓存中时

gacutil -i policy.1.2.myDLL.dll
Run Code Online (Sandbox Code Playgroud)

我得到错误:

Failure adding assembly to the cache:  This assembly is built by a 
runtime newer than the currently loaded runtime and cannot be loaded.  
Run Code Online (Sandbox Code Playgroud)

.NET Global Assembly Cache Utility的版本为2.0.50727.42,但是我通过创建新的C#.NET 2控制台项目并执行以下命令在构建环境中检查了该版本:

using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            MessageBox.Show(Environment.Version.ToString());
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

而我的Environment.Version是2.0.50727.5466。

这一切都发生在同一台计算机上,特别是我的开发人员。

我可以将myDLL.dll从\ bin \ release文件夹复制到c:\ Windows \ assembly文件夹,没问题。但是尝试将policy.1.2.myDLL.dll文件从\ bin \ release复制粘贴到\ assembly,或者尝试使用gacutil失败。

Tim*_*m B 6

问题是正在为.NET 4.x编译策略程序集。

%PROGRAMFILES(X86)%\ Microsoft SDKs \ Windows \ v7.0A \ Bin中有一个al.exe,%PROGRAMFILES(X86)%\ Microsoft SDKs \ Windows \ v7.0A \ Bin \ NETFX 4.0工具中有一个al.exe。它们都具有相同的版本号,但第一个用于.NET 2.x,而第二个用于.NET4.x。您应指定完整路径,以确保使用正确的路径。