我如何可以强制的.NET使用的组件这是在GAC的本地副本这是、副本、组件、NET

2023-09-02 01:29:36 作者:[孤患]

我有一个.NET程序集(我的控制之外的原因)的必须的是在GAC。然而,同样的组件被其他程序使用,它具有相同的程序集的旧版本的自己的副本。它必须使用它自己的拷贝,而不是无论是在GAC。正确的版本可能是更多的麻烦比它的价值在这种情况下,对于原因,我就不赘述了。我的问题是:反正是有告诉.NET:只需使用此DLL,在这里这个目录中 - 忽略无论你在GAC中找到或其他任何地方

I have a .NET assembly that (for reasons outside my control) must be in the GAC. However, the same assembly is used by another program, which has a its own copy of an older version of the same assembly. It must use its own copy and not whatever is in the GAC. Proper versioning is probably more hassle than it's worth in this case, for reasons I won't go into. My questions is: is there anyway to tell .NET: just use THIS DLL, right here in this directory - ignore whatever you find in the GAC or anywhere else.

推荐答案

确认了GAC大会和地方议会有不同的版本号(不是一个坏主意,让你的版本号,至少,自动递增野生梳理您的AssemblyVersion在程序集信息:[总成:的AssemblyVersion(1.0.0 *)])。然后,重定向程序集使用你的应用程序的配置绑定:

Make sure the GAC Assembly and local Assembly have different version numbers (not a bad idea to let your build number, at least, auto-increment by wild-carding your AssemblyVersion in AssemblyInfo: [assembly: AssemblyVersion("1.0.0.*")] ). Then, redirect your assembly binding using your app's config:

http://msdn.microsoft.com/en-us/library/2fc472t2(VS.80).aspx http://msdn.microsoft.com/en-us/library/433ysdt1(VS.80).aspx. http://msdn.microsoft.com/en-us/library/2fc472t2(VS.80).aspx http://msdn.microsoft.com/en-us/library/433ysdt1(VS.80).aspx.

在你的情况,你会不会需要assemblyBinding配置的appliesTo属性。你只需要像:

In your case, you won't need the "appliesTo" attribute of the assemblyBinding config. You just need something like:

<runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
        <dependentAssembly>
            <assemblyIdentity name="YourAssembly" publicKeyToken="AAAAAAAAAAAA" culture="neutral"/>
            <bindingRedirect oldVersion="0.0.0.0-5.2.1.0" newVersion="5.0.8.1"/>
        </dependentAssembly>
    </assemblyBinding>
</runtime>