我正在使用一些 F# 类型 (Matrix 等)来自 C#,因此我需要在我的 C# 项目中引用 FSharp.Core 程序集。到目前为止,一切都很好。
但是,显然 mscorlib.dll (v4) 中定义的某些类型在 FSharp.Core (v2) 中“重复”,例如 System.Tuple 和 System.IObservable 。我不明白为什么这是在 .Net 4 中。 Matt Ellis 特别表示他们会在他的 MSDN 文章中删除:
遭受[重复]问题的一种语言是 F#,它以前在 FSharp.Core.dll 中定义了自己的元组类型,但现在将使用 Microsoft .NET Framework 4 中添加的元组。
我已准备好忽略这种特殊的不合时宜的重复但是,如果我可以指定我想在 C# 程序中使用哪一个。例如,当我尝试使用 System.Tuple
类型时,我收到以下 C# 编译器错误:
错误 2 类型“System.Tuple”存在于“c:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.0\Profile\Client\mscorlib.dll”和“c:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.0\Profile\Client\mscorlib.dll”中\Program Files (x86)\Reference Assemblies\Microsoft\FSharp\2.0\Runtime\v2.0\FSharp.Core.dll'
显然,解决这个问题的方法是 C# 编译器命令行上的一个开关,用于为类型别名:
csc.exe MyType.cs /reference:System.Tuple`2=mscorlib.dll /reference:FSharp.Core.dll
但是,我找不到让 Visual Studio 将此参数发送到 C# 编译器的方法。
有人有解决这个问题的办法吗?
I'm using some F# types (Matrix et al) from C# and so I need to reference the FSharp.Core assembly in my C# project. So far, so good.
However, there are apparently some types defined in mscorlib.dll (v4) which are "duplicated" in FSharp.Core (v2), like System.Tuple
and System.IObservable
. I can't understand why this is in .Net 4. Matt Ellis specifically said they would be removed in his MSDN article:
One language suffering that [duplication] problem was F#, which previously had defined its own tuple type in FSharp.Core.dll but will now use the tuple added in Microsoft .NET Framework 4.
I'm ready to look past this particular unseemly duplication if I could just specify which one I want to use in my C# program, however. When I try to use the System.Tuple
type, for example, I get the following C# compiler error:
Error 2 The type 'System.Tuple' exists in both 'c:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.0\Profile\Client\mscorlib.dll' and 'c:\Program Files (x86)\Reference Assemblies\Microsoft\FSharp\2.0\Runtime\v2.0\FSharp.Core.dll'
The way around this, apparently, is a switch on the C# compiler command line which aliases the type:
csc.exe MyType.cs /reference:System.Tuple`2=mscorlib.dll /reference:FSharp.Core.dll
However, I can't find a way to get Visual Studio to send this parameter to the C# compiler.
Anyone have a solution to this?
发布评论
评论(2)
您需要引用 4.0 版本的 F# 运行时。该版本与mscorlib 4.0版本对应,不存在类型冲突。他们将在这个目录中
You need to reference the 4.0 version of the F# runtime. This version corresponds with the 4.0 version of mscorlib and does not have the conflicting types. They will be in this directory
您可以使用 C# 程序集别名解决冲突并在 C# 代码中显式限定源程序集:例如,如果您在 F# 程序集和库中都定义了元组类型。
You can resolve conflicts by using C# assembly aliases and qualifying source assembly explicitly in C# code: for example if you have Tuple type defined both in F# assembly and in you libraries.