tags:

views:

1106

answers:

6

Can you mix .net languages within a single project? So pre-compiled, I would like to call classes and methods of other source files.

For both web and apps?

In particular I'd be interested in F# and C#.

+3  A: 

you can specify the language in each assembly project (library DLL) and use several of these in the same solution, but i don't think you can mix languages within the same assembly

Steven A. Lowe
i stand corrected - you can merge assemblies in different languages into one assembly
Steven A. Lowe
+10  A: 

You can mix languages in a single assembly with ILMerge and MSBuild.

Here is a very good example about it.

CMS
a neat trick, but you still have to create separate projects for each language, which was what the question specifically asked - good to know about the post-build merge stuff though, thanks for the link!
Steven A. Lowe
Yes that's true, however in ASP .NET you can mix languages, and Visual Studio does the trick... http://tinyurl.com/4g9ohv
CMS
+2  A: 

You can do it in a web site project versus a compile-first project: http://www.aspnetlibrary.com/articledetails.aspx?article=Use-C-Sharp-and-VB.NET-in-the-same-project. A web site's BuildProvider resolves language elements on-the-fly.

.NET's BuilderProvider still isn't available for non-web site projects so you're out of luck for standard app mixed Intellisense.

Corbin March
+6  A: 

CMS mentions an interesting approach, but in reality I would suggest you keep things simple and have different assemblies (projects) for the C# and F# code. There are well documented communication points between C# and F# (such as here and here) - I'd recommend them instead. The differences between C# and F# (especially with F# having a different runtime!) are quite large...

Marc Gravell
+4  A: 

Yes, you can, but Visual Studio does not support it directly. What you will do is compile code to netmodules, then combine them into a single assembly. The compilers support the "/target:module" option which generates these netmodules.

You can then use the compilers to reference other netmodules when building, or use Assembly Linker (Al.exe). There's even an msbuild task for it: AL (Assembly Linker) Task.

A full overview is provided on MSDN: How to: Build a Multifile Assembly

MichaelGG
A: 

Visual Studio 2010 (I'm using Beta 2) let you mix F# libraries and C# project, in a very easy way. Just add them in the same solution and build all. Very interesting.

Zen