You can't mix F# and C# in a single Visual Studio project. However, Visual Studio places Projects in to Solutions, and a solution can have more than one project, and you can mix F# and C# projects.

In your case, open your C# solution, go to the Solution Explorer, right click on the top item in the tree ("Solution '...'), and click Add New Project. From this dialog, specify an F# project (under Other Projects), give it a name, and click ok.

This will give you an empty project, so add a file to it, and put you code in there. You also need to get this to compile as a DLL, so right click on the project in Solution Explorer, and you see a "Project Type:" combo, where you can pick "DLL".

Once you have that compiling, you need to reference the dll from the C# project. Under that project there should be "References" node (in Solution Explorer), so, right click that and "Add Reference". You then need to browse to the dll created in the F# project.

HTH,

Nick
[link:nholmes.wordpress.com]

By on 2/11/2008 10:01 AM ()

First of all, thanks for your quick and comprehensive answer.

However, you'll agree that code like my example would not work that way as there'd be two assemblies circularly depending on each other. Of course, there are many ways to avoid that. all of them complicating the code.

So don't you also agree that not being able to mix code of different languages within an assembly is a missing feature of .NET?

Paolo

By on 2/12/2008 7:07 AM ()

Both the C# and the F# compilers can output "modules" which are then combined using the Assembly Linker (al.exe) in to an assembly (An assembly does not necessarily imply a single file, btw).

So, you can mix code of different languages in an assembly, if you want.

However, these modules will not magically resolve your circular reference problem, because the C# compiler knows nothing of F# source, and fsc nothing of C#, you need to be able to compile at least one of them without the other.

You will need to factor out (for example) interfaces to a third assembly or module, that can be compiled. (And in my opinion, this would probably simplify the code, not complicate it.). Then use the linker to produce your final assembly.

However, that's a pain to set up (Visual Studio doesnt support this, so prepare to break out the MSBuild manual), so why not build it up as 3 separate assemblies, and use ILMerge to merge those assemblies into one?

HTH,

Nick
[link:nholmes.wordpress.com]

By on 2/12/2008 8:23 AM ()

No you can't mix different languages in Visual Studio Project.

ASP.Net might be an exception thet allow to have different langages in a project but again this is a special project type.

It is possible to create a new project type that allows to compile a single asembly but it won't be an easy task to implement a new project for Visual Studio.

If you really want to have a single assembly, you could try to compile them individually and merge them using a tool like "ILMERGE"

By on 2/12/2008 7:45 AM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper