带类型提供程序的可移植库

Nic*_*s W 8 f# type-providers portable-class-library

据我所知,F#类型提供程序总是一个非可移植的类库(例如,它将使用在WinRT中不可用的Reflection.Emit).要在我的F#类库中使用它,我需要添加对类型提供程序DLL的引用,以便该库必须是不可移植的才能编译.

在这种情况下,我很高兴分成一个便携式程序集和一个使用类型提供程序的程序集.我可以编译它的唯一方法是在我的C#应用​​程序项目(.NET 4.5)中添加对Fsharp.Core的引用 - 但是在运行时FSharp.Core的版本之间仍然存在冲突.

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

我是否可以解决冲突,我是否错误地使用了类型提供程序,还是无法完成的事情?

Bri*_*ian 8

您需要在app.config文件中进行绑定重定向.如果您创建一个目标为4.5的新F#项目,它将具有

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

在app.config中.您需要添加在最终消费EXE项目的app.config中(例如C#一个),所以如果你在桌面上运行它例如,它将解决便携式FSharp.Core(2.3.5.0)到桌面一(4.3.0.0).