开发者

Assembly redirection in code instead of app.config

I'm using ironruby to execute a script that loads an assembly with a dependency that needs to be redirected from v2.0.0.0 to v3.5.0.0 in the app.config like this:

<runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Build.Framework" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
        <bindingRedirect oldVersion="0.0.0.0-99.9.9.9" newVersion="3.5.0.0"/>
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.CompactFramework.Build.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
        <bindingRedirect oldVersion="0.0.0.0-99.9.9.9" newVersion="9.0.0.0"/>
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Build.Engine" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
        <bindingRedirect oldVersion="0.0.0.0-99.9.9.9" newVersion="3.5.0.0"/>
      </dependentAssembly>
    </assemblyBinding>
</runtime> 

The script works with this redirection, but this requires me to always change the ironruby app.config, and it applies to all scripts. I need to either:

  • define this redirection either for a single script
  • execute code that registers the redirection before requiring the problematic assembly
开发者_如何学JAVA

How?


You can avoid changing the IronRuby app.config by using a hack that I wrote called configuration_settings_hackery.rb. You can read about it on my blog. The blog post contains a link to a gist on github.

I use this hack every day, and I have been having a lot of success with it. You will need to change the last line of the configuration_settings_hackery.rb file to point to the location of your app.config. The version that I posted just looks for c:\app.config.


I would try creating a new AppDomain with AppDomainSetup.ConfigurationFile set to your special app.config and then run your script in that AppDomain.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜