使用 VS 2017 时无法解析对程序集 FSharp.Core 4.4.1.0 的依赖 [英] Cannot resolve dependency to assembly FSharp.Core 4.4.1.0 when using VS 2017

查看:12
本文介绍了使用 VS 2017 时无法解析对程序集 FSharp.Core 4.4.1.0 的依赖的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 VS 2015 和 F# 4.0 (4.4.0.0) 中开发已经有一段时间了.

I have been developing in VS 2015 and F# 4.0 (4.4.0.0) for quite some time.

随着 VS 2017 的发布,我想在最新的 VS 中打开解决方案进行开发工作,但仍将项目保留为 VS 2015、F# 4.0、.NET 4.5.2.构建服务器还必须使用 VS 2015 一段时间.

With the release of VS 2017, I want to open solutions in the newest VS for development work, but still for a while keep the projects as VS 2015, F# 4.0, .NET 4.5.2. The build server will also have to use VS 2015 for a while.

据我所知,这种场景在早期的 VS 版本升级中没有出现过问题,但后来我想我当时并没有使用 F#.

As far as I can remember, this kind of scenario has not been problematic in earlier VS version upgrades, but then I don't think I used F# at that time.

我打开解决方案并尝试编译.我在 C# 应用程序项目中收到此错误.(还有其他 C# 应用程序,并且至少有一个引用了 F# 库.)

I opened the solution and tried to compile. I get this error in a C# application project. (There are other C# applications, and at least one references an F# library.)

未知的构建错误,无法解析对程序集的依赖关系"FSharp.Core,版本=4.4.1.0,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a",因为它尚未预加载.使用 ReflectionOnly API 时,必须通过 ReflectionOnlyAssemblyResolve 事件预加载或按需加载依赖程序集.

我在解决方案中的所有 F# 项目都是 4.0 (4.4.0.0).我仔细检查过.

All my F# projects in the solution are 4.0 (4.4.0.0). I double checked.

为什么会这样?

推荐答案

我搜索了4.4.1.0",发现C#项目的obj"文件夹有一个.exe.config文件,与app不同.config.它包含项目的 app.config 中没有的额外信息.

I searched for "4.4.1.0", and discovered that the "obj" folder of the C# project had a .exe.config file that differed from the app.config. It had this extra information that is not in the app.config of the project.

<runtime>
...
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="FSharp.Core" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.4.1.0" newVersion="4.4.1.0" />
      </dependentAssembly>
    </assemblyBinding>

为什么会自动附加,为什么只在这个特定的 C# 项目中?

Why is this appended automatically, and why only in this particular C# project?

我尝试将该部分复制到项目的 app.config 中,并在两个地方将其更改为 4.4.0.0,但这不起作用.也试过把4.4.1.0"作为旧版本的上限,把4.4.0.0"作为新版本,但还是不行.同样的编译器错误.

I tried to copy that section to the app.config of the project, and change it to 4.4.0.0 in both places, but that didn't work. Also tried to use "4.4.1.0" as upper limit of old version, and have "4.4.0.0" as new version, but still didn't work. Same compiler error.

然后我删除了该部分,并在 C# 项目中引用了 FSharp.Core 4.4.0.0.终于摆脱了编译错误.

Then I removed that section, and I referenced FSharp.Core 4.4.0.0 in the C# project. That finally got rid of the compile error.

我运行了程序.它因此异常而崩溃.

The I ran the program. It crashed with this exception.

未处理的异常:无法加载文件或程序集FSharp.Core,版本=4.4.1.0,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a"或其依赖项之一.定位的程序集的清单定义与程序集引用不匹配.(来自 HRESULT 的异常:0x80131040)

我重新插入了带有重定向的部分,现在程序运行良好.

I reinserted the section with the redirect, and now the program runs fine.

总结一下,我添加了对FSharp.Core 4.0的引用,重定向如下

Just to sum up, I added a reference to FSharp.Core 4.0, and the redirect looks like this

<bindingRedirect oldVersion="0.0.0.0-4.4.1.0" newVersion="4.4.0.0" />

通过这些修改,该解决方案在 VS 2015 中仍能按预期工作.

With these modifications, the solution still works as expected also in VS 2015.

这篇关于使用 VS 2017 时无法解析对程序集 FSharp.Core 4.4.1.0 的依赖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆