Adding F# projects as references to C++/CLI projects not possible? - f#

I am trying to add an F# project as a reference to a C++/CLI project in VS 2015 but I always get the error that the reference cannot be added because it is incompatible.
Is using F# projects impossible for C++/CLI? Do I have to compile them and add the DLLs to circumvent this?
#Downvoters: Please explain why so I can improve things in the future. Thanks.

Related

How do I upgrade an F# project from .NET Framework 4.7.2 to .NET 5.0?

I've seen this question asked for C# projects but not F#.
I have a solution that is composed of multiple C# and F# projects all using framework .NET Framework 4.7.2. I've been trying to upgrade them to .NET 5 and used the Microsoft tools to do this, the .NET API Analyzer and the .NET Upgrade assistant.
I've had no problems with the C# projects (aside from some third party dependency issues), all are now upgraded but the .NET Upgrade assistant did not touch the F# projects when I ran it against the solution and won't recognise their file type .fsproj when I try to run it against them separately. So I now have a solution containing multiple frameworks which of course throws the error
"This project target a different framework"
My question is, has anyone upgraded F# projects to .NET 5? Do you have any advice on how to do this? Are there any tools to do this? I've been searching all day and have not been able to find any advice, guidance or any tools, only information around creating new F# projects but not upgrading existing ones.
My solution
I ended up using the try-convert instead of the Upgrade Assistant and that worked. I almost went with manually recreating the projects which I am sure would have worked also.

(F#) Using MathNet.Numerics in Visual Studio Professional 2013

I'm trying to use MathNet.Numerics in an F# project, and I can't seem to add it as a dependency. If I go to "Manage NuGet Packages," I can install it, but I can't add it to my References; IntelliSense and the compiler then both tell me that it can't find the package MathNet.
Problem solved - I had installed MathNet Numerics instead of MathNet Numerics for F#. Also I might not have saved my project before closing it.

Xamarin Studio f# project fails to build on OSX

I've created a simple xamarin studio f# project and and f# unit project. When I build I get
unknown-file(1,1): Error FS2020: The assembly
'Studio.app/Contents/MacOS/lib/monodevelop/AddIns/NUnit/nunit.framework.dll'
is listed on the command line.
Assemblies should be referenced using a command line flag such as
'-r'. (FS2020) (FRXUI.Spec)
I have made no source code changes after generating the template projects.
The problem is the space in the path to the file, the reference should read
/Applications/Xamarin Studio.app/Contents/MacOS/lib/monodevelop/AddIns/NUnit/nunit.framework.dll
There is currently a known issue here
You can also work around it by using nuget, I almost always use fsunit with NUnit for unit tests in F#. If you don't already have it, you can also get monodevelop-nuget-addin which makes installation of these packages pretty easy.
I got this too. I worked around it by replacing the reference to nunit.framework in my test project with a version built from source.

Metro style Apps with F#?

In the Build 2011 keynote and demos, they were always talking about C++, C#, Visual Basic and JavaScript. Can't I build Metro style Apps with F#? Or is it safe to say that if it works with C#, then it works with F# as well?
Or is it eligible to say if it works with C# then it works with F# as well?
Yes, that's how it is supposed to work. In addition to javascript and C/C++, any CLS compliant language that runs on top of the CLR will have access to the WinRT API.
Unfortunately in the VS 2011 Express edition you don't get tooling support but I guess this will be added progressively or to other editions:
Don talks about this a little around 7:40 into his talk.
http://channel9.msdn.com/Events/BUILD/BUILD2011/SAC-904T
I had the same question and created a blog post: Create a Metro App in F# (NOT)
There are a few issues:
You cannot reference ordinary .NET dll’s (even in C#). They have to
be have recompiled with a “reference” to the WinRT. Because of this
you cannot reference the F# dll. I think this will be solved when F#
3.0 get released (source: Understanding F# slide from Don Syme at
build).
The ability from F# to create Metro apps. This has to be
built by the F# team. This is an open question. This is the all-F#
approach (In WPF it is today possible but not recommended).
Tool support for creation Metro front-end projects. This will be not the case for the
F# 3.0 release. (source: Understanding F# slide from Don Syme at
build).
Using Visual Studio 11 Developer Preview (Full, not Express), I was able to reference and run F# code from a C# Metro style application with the following caveats:
You will get a build warning saying that the project can't be referenced, even though Visual Studio will still allow you to add it.
You must remove all references to all DLL's in the F# project, including FSharp.Core.
By following these steps it is possible to run F# code from a C# Metro style application, but it is nearly impossible to write any useful code in F# without references to the core language libraries. Let's hope they update the libraries to be WinRT compatible soon.
The question has been answered here:
Windows 8 and F#
Although you cannot create and design Metro apps directly in F#, you can still create so called Portable library in F# with all Models and ViewModels and use it in another Metro projects. It's not ideal, but it works.
I ported my stock chart library for .NET3.5-4.0 to Portable library,it works quite well on Metro with C# Metro application and some my Metro UI bridge.
I'm convinced that I can use F# to make Metro application in many parts.

Web Project for F#

I am building a project system for Visual Studio MVC web projects with controllers written in F#. It comes along pretty cool. I can build and run the apps, but I have a problem with FSharp Language Service.
In the editor it shows the syntax colorization and diagnostic as it should. With one problem - it does not pick up project references. Even though during build it picks them up and successfully builds the project, on the screen it shows the objects/namespaces from the referenced assemblies/projects as unresolved.
If somebody out here has some knowledge about integrating with F# Language service - please help me make it work
In response to Tomas:
The code for F# controllers is in the project file and as I already mentioned I can compile and run it. Originally we kept the F# code in a separate project and desire to get rid of this extra complexity is what prompted this project. It is not a ASP.MVC though it is Bistro MVC.
Edit
BistroMVC now solves this problem in the latest version of the Bistro Designer which is based on the F# project extender
Do you keep your F# source code as part of the Web Project? I'm not sure if this is even possible for ASP.NET MVC, but it was possible in ASP.NET WebForms. With WebForms projects, it didn't work very well (because F# wasn't aware of the project context). I believe it was possible to overcome this with a hacky #if like this:
#if EDITING
#r "Your.Referenced.Library.dll"
#endif
This would serve only as a hint to the editor... However it is much better idea (if it is possible) to write F# controllers in a separate F# project. In that case you shouldn't have any issues (at least I hope so!)
Can you describe what you're doing in more detail? Is this a "flavoring", or a new project system? Are other aspects of the 'project environment' picked up? For example, if you have F# code with
#if DEBUG
let x = 3
#else
let x = 4
#endif
does the coloring change when you change the VS solution from Debug to Release?
(Offhand I am unsure if it will be possible to fully integrate the F# language service into a user-defined project system; if you want more of a discussion, you can email fsbugs#microsoft.com and I'll respond there.)

Resources