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

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

问题描述

注意:这里我谈论的是dotnet核心,而不是完整的框架!对于完整的框架,有很多文档,但这是dotnet核心。

我有一个

dotnet new --lang F#

还有一个ASP.NET Core RC2 C#应用程序(由VS中的File-> New Project创建)。

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#应用程序(此处使用控制台应用程序,但是

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.

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

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