Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to mix .cs (C#) and .fs (F#) files in a single Visual Studio Windows Console Project? (.NET)

How to do it? Is it possible to call a function from one F# code into C# without using a separated dll file or project?

like image 760
Jader Dias Avatar asked Jan 21 '09 17:01

Jader Dias


People also ask

Can you mix VB and C# in same project?

Hi, you cannot use C# and VB in the same project, but you can use C# projects and VB projects in the same solution. I would suggest breaking up the work into seperate projects, but ideally you would both use the same language which would make working on eachothers code a lot easier. Mark.

Can you use C# in Visual Basic?

Universal Windows PlatformWindows 10 apps you build with C# and Visual Basic run as fast as C++ with the . NET Native runtime.

How do I create a .CS file?

Open the command prompt tool and go to the directory where you saved the file. Type csc helloworld. cs and press enter to compile your code. If there are no errors in your code, the command prompt takes you to the next line and generates helloworld.exe executable file.


2 Answers

You can't include two different languages in the same project, but you can merge them using ilmerge. To do this, put both projects in the same solution and reference the F# module as you would any dll. As part of your deployment script, run ilmerge to combine the exe file and dll file into a single exe file. See this Code Project article that details how to use ilmerge to create an exe.

like image 82
Michael Meadows Avatar answered Sep 18 '22 20:09

Michael Meadows


Not being able to mix C# and F# in the same project creates a problem; It leads to circular dependencies between the two projects. Conceptually there is only one project containing two languages, but because of the way visual studio manages projects languages cannot be mixed, leading to circular dependencies.

For now the only solution I see it to create a lot of interfaces in a third project and have one of the project refer to the interfaces project, instead of the real project. Is there a better way?

Kind Regards, Nick

like image 27
nreyntje Avatar answered Sep 19 '22 20:09

nreyntje