Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't reference an F# class library

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?

like image 761
Rob Lyndon Avatar asked Jun 28 '16 14:06

Rob Lyndon


2 Answers

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)
like image 120
gregkalapos Avatar answered Sep 29 '22 14:09

gregkalapos


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.

like image 32
Rob Lyndon Avatar answered Sep 29 '22 16:09

Rob Lyndon