开发者

GAC Assembly version to use based on Web.Config

Good Day

I have a project that makes use of custom assemblies in the GAC: To be able to use that, I added a Reference to my project in

C:\WINDOWS\Microsoft.NET\assembly\GAC_MSIL\JOHN.CommonLib\v4.0_1.0.0.0__9cd884563ebafb62\JOHN.CommonLib.dll

(CopyLocal=False; SpecificVersion=False) Also, i added this in the Web.Config file

<compilation debug="false" strict="true" explicit="true" targetFramework="4.0" >
  <assemblies>
    <add assembly="JOHN.CommonLib, Version=1.0.0.0, Culture=neutral, PublicKeyToken=9cd884563ebafb62"/>        
  </assemblies >
</compilation >

It's running as expected. The problem is when i install a new version I install a new version to the GAC, and change the Web.Config accordingly

<add assembly="JOHN.CommonLib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=9cd884563ebafb62"/>

JOHN.CommonLib is a tester Class Library that returns either "1.0" or "2.0" depending on the version.

Issue: If I compile using 1.0, the webapps that make use of it always shows "1.0" even if i change the Web.Config between 1.0 and 2.0 I would like my web app to use the version that i write in my Web.Config

Any 开发者_开发问答ideas? I also stop and start the AppPool in between changing the Web.Config.


For strong named assemblies - application will always bind (if possible) to the version that it has been built with. To override this binding, you need to specify binding redirection for the assembly. There are multiple ways to do that - see this link. So one of the way to use app/web config file - for example,

<configuration>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="JOHN.CommonLib"
          publicKeyToken="9cd884563ebafb62"
          culture="en-us" />
        <!-- Assembly versions can be redirected in application, 
          publisher policy, or machine configuration files. -->
        <bindingRedirect oldVersion="1.0.0.0" newVersion="2.0.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜