.Net Redirecting requested assemblies to different version

你。 提交于 2019-12-11 11:15:34

问题


I have an assembly that is version 1.0.0.0 and a new version that is 2.0.0.0. Both are installed in my GAC.

Currently I can use the "Configured Assemblies" section in the ".NET Framework 2.0 Configuration" tool to enforce that any requests for 1.0 are sent to the 2.0 assembly on my server. This still works the same with 4.0 framework but I need to install teh .Net 2.0 SP1 to get the 2.0 configuration tool. I believe you can also do this with "Publisher Policies" but these seem to be a bit more of a pain because you have to create a serparate assembly to perform the redirection.

With the other changes that are being made to the security model in .Net 4.0 and the fact that the ".NET Framework 2.0 Configuration" tool has not been installed by default nor updated since 2.0 I wanted to know; is there is any other more preferred way to enforce a server wide redirect for certain requested versions of a .Net assembly?


回答1:


Jay you can do what you need in the app config file (web.config or app.config) or also in the machine config. I personally would not install .NET 2.0 SP1 only to get that configuration tool.

here an example taken from: Redirecting Assembly Versions

<configuration>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="myAssembly"
          publicKeyToken="32ab4ba45e0a69a1"
          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>
      <dependentAssembly>
      <assemblyIdentity name="mySecondAssembly"
        publicKeyToken="32ab4ba45e0a69a1"
        culture="en-us" />
        <!-- Publisher policy can be set only in the application 
          configuration file. -->
        <publisherPolicy apply="no" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>


来源:https://stackoverflow.com/questions/7387959/net-redirecting-requested-assemblies-to-different-version

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!