2013-06-12 21 views
2

这里的情况:gacutil和环境造成重大头痛的小版本差异

我有一个在.NET 2中编译的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> 

然后我用汇编器来创建策略文件:

al /link:myDLL.dll.config /out:policy.1.2.myDLL.dll /keyfile:myDLL.snk 

但是,当我尝试将政策文件加载到使用

全局程序集缓存
gacutil -i policy.1.2.myDLL.dll 

我得到的错误:

Failure adding assembly to the cache: This assembly is built by a 
runtime newer than the currently loaded runtime and cannot be loaded. 

的.NET全局程序集缓存实用程序的版本是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()); 
     } 
    } 
} 

和我Environment.Version是2.0.50727.5466。

这一切发生在同一台计算机上,具体而言,我开发框。

我可以从\ Bin \ Release文件复制到MYDLL.DLL C:\ WINDOWS \ assembly文件夹,没有问题。但是,试图要么复制过去从\ BIN \发布policy.1.2.myDLL.dll文件\组装,或使用GACUTIL失败。

+0

http://social.msdn.microsoft.com/Forums/en-US/biztalkgeneral/thread/e76f5c46-e679-4923-bf9d-1f883074eb2e/? –

+0

您确定您使用的是.NET 2.x版本的al? –

+0

@TimB我不确定。我打开了一个新的Visual Studio 2010命令提示符,输入“al”,得到了“Assembly Linker version 10.0.30319.1'。在全局程序集缓存中使用dll时,我有点新意。 – CurtisHx

回答

4

的问题是,政策组件被编译为.NET 4.x版

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

+0

谢谢蒂姆。只是谢谢你。 – Thomas