Can you mix .net languages within a single project?

后端 未结 5 837
暗喜
暗喜 2020-12-01 06:35

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?

<
相关标签:
5条回答
  • 2020-12-01 07:17

    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

    0 讨论(0)
  • 2020-12-01 07:21

    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

    0 讨论(0)
  • 2020-12-01 07:32

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

    Here is a very good example about it.

    0 讨论(0)
  • 2020-12-01 07:34

    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.

    0 讨论(0)
  • 2020-12-01 07:36

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

    0 讨论(0)
提交回复
热议问题