8

This issue is exactly as described in the title.

I have a portable F# class library. I have created an ASP.NET Core Web Application (both .NET Framework and .NET Core), from which I have tried to add a reference to my F# class library.

Trying to add the reference gives a message:

The following projects are not supported as references:

Project type is unsupported by current project and can not (sic) be referenced.

This is extremely disappointing, as the .NET Core is now in General Availability.

Are there any workarounds while this bug gets addressed?

Community
  • 1
  • 1
Rob Lyndon
  • 12,089
  • 5
  • 49
  • 74

2 Answers2

4

I have a project, which I started with Beta8 bits of .net core and since then I have an F# library, which I use from an asp.net core C# app. (btw here is an RC2 based minimal sample for referencing the F# lib from a net core based console app)

Here is how I did it:

Currently (according to my knowledge) there is no template in VS to create a coreCLR based F# library (the PLC templates under F# are all Full framework based, but that you still cannot reference from asp.net core even if it runs on full framework), so you have to do this with the command line. This is done by:

dotnet new --lang F#

This creates you a hello world coreCLR F# app. You can turn the app into a class library by modifying project.json file.

If you have a VS solution and you click to “Add” -> “Existing project” you can select the project.json file. This way you add it to your solution (and btw. an xproj file will be also created).

So at this point you will have the coreCLR based F# project in your solution. I believe by right clicking the asp.net core project and go to “Add” -> “Reference” -> Projects->Solutions and selecting the F# library you can already reference it. If this does not work, you can do it manually: just list the F# project under the “dependencies” in the project.json of the asp.net core application.

If your asp.net core app runs on full framework still need to do these steps. It actually doesn't really matter.

Now the bad part:

  • In the RTM (released on Monday) the “dotnet new” command creates an uncompliable F# app, because of some dependency issues. This is tracked here (the title says "on macOS", but it's the same on Windows) and as soon as it’s solved this should be fine (or if you did not yet install RTM and you have RC2 you are also good).
  • Intellisense and debugging across F# and C# does not work (I posted it here)
Community
  • 1
  • 1
gregkalapos
  • 3,529
  • 2
  • 19
  • 35
  • is there any more recent info on this? I'm trying to get an F# class library working in a solution with other C# asp.net core projects, but not having any luck. Is there a good example of a currently working project.json for this scenario? – Joe Audette Sep 15 '16 at 20:35
  • @JoeAudette Here is a more detailed description with a sample solution: http://kalapos.azurewebsites.net/referencing-an-f-library-from-c-on-net-core According to my knowledge that is the current stage (and that is how I work today...). According to the roadmap "Better IDE experience with workspace support on the F# language service" will come in the RTM tooling (what that exactly means i don't know..) https://blogs.msdn.microsoft.com/dotnet/2016/07/15/net-core-roadmap/ – gregkalapos Sep 15 '16 at 21:01
  • @gegkalapos, thanks! the problem I'm having is my F# class library I want to make a Controller, in project.json I have added the needed dependencies but VS says the namespace is not available on this line in my code, like it doesn't see the dependencies I'm referencing: open Microsoft.AspNetCore.Mvc – Joe Audette Sep 16 '16 at 12:25
  • wait, I see, the project does build with no errors even though VS underlines and shows errors. that will make it hard to know real errors, but it shows without errors if I open the folder in VS Code so maybe that is where I should work when editing the F# and just use VS 2015 for working in the C# code? – Joe Audette Sep 16 '16 at 12:34
  • @JoeAudette: well, I don't really use VS code... somehow I like the full VS better and I just ignore the "Error List" window. During compilation I alway look at the "Output" window.. that shows the real errors (if there are any) from the compiler. But of course if this is handled better in VS Code that is maybe even more convenient. But yeah..the bottom line is: the current tooling is not 100% ready yet, so everyone uses some kind of workaround.. – gregkalapos Sep 16 '16 at 12:44
  • thanks for your help! despite the errors that vs shows I got a proof of concept controller working in an F# class library, with the view living in the main c# web app. at least editing in VS code I don't see errors and then I compile it in vs 2015 and though it shows errors the build output says no errors – Joe Audette Sep 16 '16 at 13:02
1

Although .NET Core has officially been released, the vast majority of the nuget packages in the ASP.NET Core Web Application are in prerelease. Moreover, although the entity framework identity model has been cleaned up, my attempt to change the key columns for users and roles from strings to ints generated an obscure error when I tried to implement Entity Framework migrations. I know I can do it for a .NET Web Application, even though the process is clunky in places. So for now I have gone back to using a .NET Framework Web Application. I'm looking forward to seeing a fully mature version of ASP.NET Core Web Applications. It's not ready, but it looks very promising.

Rob Lyndon
  • 12,089
  • 5
  • 49
  • 74