本文介绍了如何使 FSI 在 NET5 下工作并生成愚蠢的 stackoverflow 消息“标题不能包含..."闭嘴?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将一个相当小的 F# 项目从 Net Framework 迁移到 NET5.迁移非常简单,一切正常,包括测试.

I am migrating a fairly small F# project from Net Framework to NET5. The migration was very easy and everything works including the tests.

但是,当我运行一些脚本时,我现在收到以下错误:

However, when I run some scripts I am now getting the following error:


Microsoft (R) F# Interactive version 11.0.0.0 for F# 5.0
Copyright (c) Microsoft Corporation. All Rights Reserved.

For help type #help;;

> 
[Loading C:UserskkkmaAppDataLocalTemp
uget28772--091a5e4a-2a27-4d4d-9891-2b58055c5317Project.fsproj.fsx
 Loading C:GitHubBerremanBerremanAnalyticsExamplesReferences.fsx]
namespace FSI_0002.Project

namespace FSI_0002

[Loading C:UserskkkmaAppDataLocalTemp
uget28772--091a5e4a-2a27-4d4d-9891-2b58055c5317Project.fsproj.fsx]
namespace FSI_0003.Project

Binding session to 'C:WindowsMicrosoft.NETFramework64v4.0.30319System.Runtime.dll'...
Binding session to 'C:WindowsMicrosoft.NETFramework64v4.0.30319System.Runtime.Numerics.dll'...
System.TypeLoadException: Could not load type 'System.ICloneable' from assembly 'System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
   at Berreman.MathNetNumericsMath.complexDiagonalMatrix(Int32 n, Complex e)
   at Berreman.Geometry.complexIdentityMatrix(Int32 n) in C:GitHubBerremanBerremanBerremanGeometry.fs:line 17
   at Berreman.Geometry.ComplexMatrix3x3.get_identity() in C:GitHubBerremanBerremanBerremanGeometry.fs:line 307
   at Berreman.MaterialProperties.Eps.fromRefractionIndex(RefractionIndex _arg1) in C:GitHubBerremanBerremanBerremanMaterialProperties.fs:line 70
   at FSI_0004.opticalProperties(RefractionIndex refractionIndex) in C:GitHubBerremanBerremanAnalyticsExamplesGlass_01.fsx:line 51
   at FSI_0004.getGlassInfo(Boolean useThickPlate, RefractionIndexThickness nh1, FSharpOption`1 nh2Opt, IncidentLightInfo light) in C:GitHubBerremanBerremanAnalyticsExamplesGlass_01.fsx:line 61
   at <StartupCode$FSI_0004>.$FSI_0004.main@() in C:GitHubBerremanBerremanAnalyticsExamplesGlass_01.fsx:line 98
Stopped due to error
> 

当我从 C:UserskkkmaAppDataLocalTempuget28772--091a5e4a-2a27-4d4d-9891- 检查 Project.fsproj.resolvedReferences.paths 时2b58055c5317(这是我运行脚本时 FSI 创建的文件夹)我看到它从 C:Userskkkma.nugetpackagesmicrosoft.netframework.referenceassemblies.net481.0 开始.0uild.NETFrameworkv4.8FacadesSystem.Runtime.InteropServices.RuntimeInformation.dll 并且它还有一些其他的 Net Framework 解析引用.这让我相信 FSI 以某种方式决定"了使用 Net Framework 而不是 NET 5.

When I examine Project.fsproj.resolvedReferences.paths from C:UserskkkmaAppDataLocalTempuget28772--091a5e4a-2a27-4d4d-9891-2b58055c5317 (and that's the folder created by FSI when I run the script) I see that it starts from C:Userskkkma.nugetpackagesmicrosoft.netframework.referenceassemblies.net481.0.0uild.NETFrameworkv4.8FacadesSystem.Runtime.InteropServices.RuntimeInformation.dll and it also has some other Net Framework resolved references. Which makes me believe that FSI somehow "decides" to use Net Framework instead of NET 5.

文件 fsi.runtimeconfig.json 包含正确的信息:

The file fsi.runtimeconfig.json contains correct information:

{
  "runtimeOptions": {
    "tfm": "net5.0",
    "framework": {
      "name": "Microsoft.NETCore.App",
      "version": "5.0.0"
    }
  }
}

有没有人知道如何强制 FSI 选择 NET 5 而不是 Net Framework?

Does anyone have an idea how to force FSI pick up NET 5 instead of Net Framework?

推荐答案

截至 Visual Studio 2019 16.9 版,您可以启用使用 dotnet fsi 运行交互式 F# 脚本的选项.这适用于 .NET 5 代码.

As of Visual Studio 2019 version 16.9, you can enable an option to use dotnet fsi to run interactive F# scripts. This works with .NET 5 code.

这是通过工具设置的 >选项 >F# 工具 >F#互动 >使用 .NET Core 脚本.

This is set via Tools > Options > F# Tools > F# Interactive > Use .NET Core Scripting.

完整的详细信息和说明可以在 https://devblogs.microsoft.com/dotnet/f-and-f-tools-update-for-visual-studio-16-9/

Full details and instructions can be found at https://devblogs.microsoft.com/dotnet/f-and-f-tools-update-for-visual-studio-16-9/

这篇关于如何使 FSI 在 NET5 下工作并生成愚蠢的 stackoverflow 消息“标题不能包含..."闭嘴?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 23:04