你能在一个项目中混合使用.net语言吗?

时间:2021-10-19 20:48:52

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

你能在一个项目中混合使用.net语言吗?所以预编译,我想调用其他源文件的类和方法。

For both web and apps?

对于网络和应用程序?

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

特别是我对F#和C#感兴趣。

5 个解决方案

#1


15  

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

您可以将单个程序集中的语言与ILMerge和MSBuild混合使用。

Here is a very good example about it.

这是一个非常好的例子。

#2


11  

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.

是的,您可以,但Visual Studio不直接支持它。你要做的是将代码编译为netmodules,然后将它们组合成一个程序集。编译器支持生成这些netmodule的“/ target:module”选项。

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.

然后,您可以在构建时使用编译器引用其他netmodule,或使用Assembly Linker(Al.exe)。甚至还有一个msbuild任务:AL(程序集链接器)任务。

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

MSDN上提供了完整的概述:如何:构建多文件程序集

#3


8  

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

CMS提到了一种有趣的方法,但实际上我建议你保持简单,并为C#和F#代码提供不同的程序集(项目)。 C#和F#之间有很好的通信点(比如这里和这里) - 我推荐它们。 C#和F#之间的差异(尤其是F#具有不同的运行时!)非常大......

#4


2  

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

你可以在每个汇编项目(库DLL)中指定语言,并在同一个解决方案中使用其中的几个,但我认为你不能在同一个程序集中混合语言

#5


2  

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.

您可以在网站项目而不是编译第一个项目中执行此操作:http://www.aspnetlibrary.com/articledetails.aspx?article = Use-C-Sharp-and-VB.NET-in-the-same-项目。网站的BuildProvider即时解析语言元素。

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

.NET的BuilderProvider仍然不适用于非网站项目,因此您对标准app混合Intellisense运气不利。

#1


15  

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

您可以将单个程序集中的语言与ILMerge和MSBuild混合使用。

Here is a very good example about it.

这是一个非常好的例子。

#2


11  

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.

是的,您可以,但Visual Studio不直接支持它。你要做的是将代码编译为netmodules,然后将它们组合成一个程序集。编译器支持生成这些netmodule的“/ target:module”选项。

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.

然后,您可以在构建时使用编译器引用其他netmodule,或使用Assembly Linker(Al.exe)。甚至还有一个msbuild任务:AL(程序集链接器)任务。

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

MSDN上提供了完整的概述:如何:构建多文件程序集

#3


8  

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

CMS提到了一种有趣的方法,但实际上我建议你保持简单,并为C#和F#代码提供不同的程序集(项目)。 C#和F#之间有很好的通信点(比如这里和这里) - 我推荐它们。 C#和F#之间的差异(尤其是F#具有不同的运行时!)非常大......

#4


2  

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

你可以在每个汇编项目(库DLL)中指定语言,并在同一个解决方案中使用其中的几个,但我认为你不能在同一个程序集中混合语言

#5


2  

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.

您可以在网站项目而不是编译第一个项目中执行此操作:http://www.aspnetlibrary.com/articledetails.aspx?article = Use-C-Sharp-and-VB.NET-in-the-same-项目。网站的BuildProvider即时解析语言元素。

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

.NET的BuilderProvider仍然不适用于非网站项目,因此您对标准app混合Intellisense运气不利。