C# - .NET Core 上的 Visual Studio 2015 中的 F# 互操作支持 [英] C# - F# Interop support in Visual Studio 2015 on .NET Core

查看:14
本文介绍了C# - .NET Core 上的 Visual Studio 2015 中的 F# 互操作支持的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

注意:这里我说的是 dotnet 核心而不是完整的框架!对于完整的框架,有很多关于此的文档,但这是 dotnet 核心.

我有一个由

dotnet new --lang F#

以及一个 ASP.NET Core RC2 C# 应用程序(由文件->VS 中的新建项目创建).

And an ASP.NET Core RC2 C# application (created by File->New Project in VS).

现在我使用来自 C# 的 F# 库(我猜这是一个非常常见的场景......).F# 项目在 project.json 中被引用为任何其他 .net 库(通过在依赖项下列出它)

Now I use my F# library from C# (I guess a very common scenario…). The F# project is referenced in the project.json as any other .net library (by listing it under dependencies)

现在所有这些都可以编译并运行良好,这太棒了!

Now all this compiles and works fine, which is great!

唯一的问题是VS似乎不支持它.没有智能感知和行,我在 C# 中使用 F# 函数的地方被标记为错误.从 C# 调试到 F# 也不起作用.我在带有 VS Code 的 Mac 上尝试过,同样......

The only problem is that VS does not seem to support it. There is no intellisense and lines, where I use the F# functions from C# are marked as error. Debugging from C# to F# does not work either. I tried it on a Mac with VS Code, same there…

当我点击编译时,编译器会解决这个问题,一切都很好.

When I hit compile, the compilers figure this out and everything is fine.

此屏幕截图对其进行了总结(这是我从 C# 调用 F# 函数的地方):

This screenshot summarizes it (this is where I call an F# function from C#):

所以基本上我最终得到了带有一堆错误的 VS 解决方案,但仍然可以编译.

So basically I ended up with VS solution with a bunch of errors in it, which still compiles.

这里是一个简单的复制器.

问题:

  1. 智能感知和调试应该在 VS 中工作吗?
  2. 如果是,我做错了什么?
  3. 如果否,此方案是否计划包含在未来?

这里是复制器的代码:

F# 库 - project.json(由 cli 创建 - dotnet new --lang F#)

F# library - project.json (created by cli - dotnet new --lang F#)

  "version": "1.0.0-*",
  "buildOptions": {
    "compilerName": "fsc",
    "compile": {
      "includeFiles": [
        "FSharpLibrary.fs"
      ]
    }
  },
  "dependencies": {
    "Microsoft.FSharp.Core.netcore": "1.0.0-alpha-160316",
    "NETStandard.Library": "1.5.0-rc2-24027"
  },
  "tools": {
    "dotnet-compile-fsc": {
      "version": "1.0.0-*",
      "imports": [
        "dnxcore50",
        "portable-net45+win81",
        "netstandard1.3"
      ]
    }
  },
  "frameworks": {
    "netstandard1.5": {
      "imports": [
        "portable-net45+win8",
        "dnxcore50"
      ]
    }
  }

F# 库,代码:

namespace FSharpLibrary

module Sample =

    let public FSharpFunction number = 
            printfn "Hello From F#, %d" number

C# 应用程序(这里我使用控制台应用程序,但与 asp.net core 相同)

C# application (here I use a console app, but same things as with asp.net core)

using System;
namespace ConsoleAppCSharp
{
    public class Program
    {
        public static void Main(string[] args)
        {
            FSharpLibrary.Sample.FSharpFunction(42); //<- This is red. and marked as error.     
            Console.ReadKey();
        }
    }
}

C# 控制台应用程序 project.json

C# console application project.json

{
  "version": "1.0.0-*",
  "buildOptions": {
    "emitEntryPoint": true
  },

  "dependencies": {
    "LibraryFSharp": "1.0.0-*",
    "Microsoft.NETCore.App": {
      "type": "platform",
      "version": "1.0.0-rc2-3002702"
    }
  },

  "frameworks": {
    "netcoreapp1.0": {
      "imports": "dnxcore50"
    }
  }
}

谢谢

推荐答案

所以目前我上面描述的是您在 Visual Studio 2015 中使用预览工具获得的所有支持.Visual Studio 15 有望更好,但当前的预览版(预览版 5)根本不支持 .NET Core.

So currently what I described above is all the support you have in Visual Studio 2015 with the preview tooling. Visual Studio 15 will be hopefully better, but the current Preview (Preview 5) does not have .NET Core support at all.

值得一试的是 Visual Studio Code.在 F# 中,您可以获得 C# 中定义的类型的智能感知.所以对于 F#-C# 的互操作性,目前 VS Code 比完整的 VS 有更好的支持.

What is worth trying out is Visual Studio Code. In F# you get intellisense for type which are defined in C#. So for F#-C# interopability currently VS Code has much better support than the full VS.

这篇关于C# - .NET Core 上的 Visual Studio 2015 中的 F# 互操作支持的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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