.net 在代码中而不是在app.config中进行程序集重定向

.net 在代码中而不是在app.config中进行程序集重定向,.net,ironpython,ironruby,.net,Ironpython,Ironruby,我正在使用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.Frame

我正在使用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,并且它适用于所有脚本。 我需要:

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

如何操作?

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

您可以使用我编写的名为
configuration\u settings\u hackery.rb
的黑客来避免更改IronRuby
app.config
。你可以在我的博客上。这篇博文包含一个指向github的要点的链接


我每天都使用这个黑客,而且我已经用它取得了很多成功。您需要更改
configuration\u settings\u hackery.rb
文件的最后一行,以指向
app.config
的位置。我发布的版本只是寻找
c:\app.config

哦,这看起来“不错”。我将在周末尝试:)好的,进一步调查后,我不确定这是否有效。虽然这适用于配置值,但不适用于程序集绑定。我想我可能需要连接到events.net Fire以进行程序集解析。