系统范围的绑定重定向为F#4.0.0.0到4.3.0.0

nic*_*las 6 .net f# assembly-binding-redirect

我有一些xUnit测试失败的常见

Could not load file or assembly 'FSharp.Core, Version=4.0.0.0, Culture=neutral, 
PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. 
The system cannot find the file specified.
Run Code Online (Sandbox Code Playgroud)

为了执行机器范围的重定向,我添加到文件中

C:\Windows\Microsoft.NET\Framework\v4.0.30319\Config\machine.config 

<runtime>
  <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
    <dependentAssembly>
      <assemblyIdentity name="FSharp.Core" publicKeyToken="b03f5f7f11d50a3a"
                        culture="neutral"/>
      <bindingRedirect oldVersion="4.0.0.0" newVersion="4.3.0.0"/>
    </dependentAssembly>
  </assemblyBinding>
</runtime>
Run Code Online (Sandbox Code Playgroud)

你有更好的方法来处理4.0/4.3问题吗?

Bri*_*ian 3

我不知道 xUnit,但如果您的单元测试运行程序支持 app.config 文件,您只需将配置附加到单元测试程序集(例如,沿着使用默认 F# 控制台应用程序模板获得的内容的 app.config 即可) )。如果测试运行程序不尊重 app.config,那么我认为 machine.config 策略是一个不错的策略。