【问题标题】:Assembly redirection in code instead of app.config代码中的程序集重定向而不是 app.config
【发布时间】:2010-01-14 23:46:42
【问题描述】:

我正在使用 Ironruby 执行一个脚本,该脚本加载具有依赖项的程序集,该依赖项需要在 app.config 中从 v2.0.0.0 重定向到 v3.5.0.0,如下所示:

<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> 

该脚本适用于此重定向,但这需要我始终更改 ironruby app.config,它适用于所有脚本。 我需要:

  • 为单个脚本定义此重定向
  • 在需要有问题的程序集之前执行注册重定向的代码

怎么做?

【问题讨论】:

    标签: .net ironpython ironruby


    【解决方案1】:

    您可以避免更改 IronRuby app.config,方法是使用我编写的名为 configuration_settings_hackery.rb 的 hack。你可以在我的博客上read about it。该博客文章包含指向 github 上的要点的链接。

    我每天都在使用这个 hack,而且我已经取得了很大的成功。您需要将configuration_settings_hackery.rb 文件的最后一行更改为指向app.config 的位置。我发布的版本只是寻找c:\app.config

    【讨论】:

    • 哦,这看起来“不错”。我会在周末尝试一下:)
    • 好的,经过进一步调查,我不确定这是否可行。虽然这适用于配置值,但不适用于程序集绑定。我想我可能需要连接到 .net 触发的事件以进行程序集解析。
    【解决方案2】:

    我会尝试创建一个新的AppDomain 并将AppDomainSetup.ConfigurationFile 设置为您的特殊app.config,然后在该AppDomain 中运行您的脚本。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-02-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-20
      • 2018-07-20
      相关资源
      最近更新 更多