Can you mix .net languages within a single project

2019-01-11 01:17发布

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#.

标签: c# .net f#
5条回答
趁早两清
2楼-- · 2019-01-11 02:07

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.

查看更多
Melony?
3楼-- · 2019-01-11 02:08

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

查看更多
萌系小妹纸
4楼-- · 2019-01-11 02:11

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...

查看更多
【Aperson】
5楼-- · 2019-01-11 02:15

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

查看更多
smile是对你的礼貌
6楼-- · 2019-01-11 02:24

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

Here is a very good example about it.

查看更多
登录 后发表回答