15

Note: here I talk about dotnet core and not full framework! For full framework there are plenty of docs on this, but this is dotnet core.

I have an F# library created by

dotnet new --lang F#

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

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!

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.

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

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

Here is a simple reproducer.

Questions:

  1. Should intellisense and debugging work in VS at all?
  2. If yes, what did I do wrong?
  3. If no, is this scenario planned to be covered in the future?

Here is the code from the reproducer:

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# library, the code:

namespace FSharpLibrary

module Sample =

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

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# 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"
    }
  }
}

Thanks

gregkalapos
  • 3,529
  • 2
  • 19
  • 35
  • I have deleted my answer, thought it might have been better to leave it there incase someone else thought of answering the same as I did - that's the whole point of a QA site, a question gets asked, and multiple answers are provided both within and out of context. I have found the following for you: https://github.com/Microsoft/visualfsharp/wiki/F%23-for-CoreCLR---Status It would seem debugging is not supported just yet, it also seems to have poor VS support at the moment. – Eon Jun 09 '16 at 10:35
  • @Krohn I added to the question that this is not full framework, so I think there won't be any new answer with that. Thanks for the github page. I already saw that and that really says that it is not supported, but that page was updated on 27 January last time, which was before the RC1/Preview1 release of ASP.NET Core, so I'm not sure that it is 100% accurate. – gregkalapos Jun 09 '16 at 11:08
  • 1
    Allright, so based on the github discussions what I discribed here is the current stage and intellisense and debugging are not supported: https://github.com/dotnet/roslyn-project-system/issues/219 https://github.com/Microsoft/visualfsharp/issues/1193 https://github.com/Microsoft/visualfsharp/issues/496 – gregkalapos Jun 09 '16 at 11:33
  • As I know .NET core for F# is still in development, it will be released with F# 4.1 and Visual studio 15. – Stefano Balzarotti Nov 13 '16 at 20:55
  • 1
    @StefanoBalzarotti The .NET Core release is independent from the VS release and from the F# version. Currently the tooling is not great, but it works.. (btw. it is both for C# and F# in preview stage) VS Code even has intellisense for interop cases. But yes, with high probability VS15 will have better support. What I want to point out: it is already possible to use F# on .NET Core today with some drawbacks. – gregkalapos Nov 13 '16 at 21:15
  • @gregkalapos Thanks, I had a lot of interest in using F# with .NET Core. I'm following the project on github: https://github.com/Microsoft/visualfsharp/wiki/F%23-for-CoreCLR---Status, and as I see, the last build supports .NET Core, but is still in development and they have not yet released a stable release. And as I know they plan to release full support for .NET Core with F# 4.1, and the new versions follows the roadmap of VS15. https://visualstudio.uservoice.com/forums/121579-visual-studio-ide/suggestions/7542181-add-f-support-for-net-native – Stefano Balzarotti Nov 13 '16 at 21:26

1 Answers1

2

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.

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.

gregkalapos
  • 3,529
  • 2
  • 19
  • 35