如何从C#添加到F#便携式库的引用便携式类库(PCL) [英] How do I add a reference to F# Portable Library from C# Portable Class Library (PCL)

查看:519
本文介绍了如何从C#添加到F#便携式库的引用便携式类库(PCL)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含两个F#项目中,我想写一些的xUnit测试C#项目一期工程:




  • FS_PL:F#3.1(3.3.1.0)便携式图书馆

  • FS_PL_Legacy:F#31(2.3.5.1)便携式图书馆(传统)

  • 测试: C#.NET 4.5 / Win8的C#便携式类库(PCL)



我无法从测试添加引用无论是F#的库。



当我尝试添加到FS_PL一个参考,我提出了一个对话框,指出无法引用添加到项目'FS_PL'的目标便携式库项目FS_PL是不一样的,或与当前的便携式库项目的目标兼容:



这是奇怪,因为我的测试和FS_PL库都被配置为针对.NET 4.5和放大器; Windows 8的。



因此,我创建FS_PL_Legacy并尝试添加对它的引用。这样做让我非常的'有用'的消息,指出无法添加引用到项目'FS_PL_Legacy':



有谁知道我做错了?



部分解决方法#1



从的 a连接问题,讨论这个问题,我增加了以下到C#项目:

 <&的ItemGroup GT; !
< - 手动添加引用F#项目要克服的问题在这里讨论:
http://stackoverflow.com/questions/23111782/how-do-i-add-a-reference-to -f便携库 - 从-C锋利便携类溴化锂
- >
< ProjectReference包括=.. \FS_PL\FS_PL.fsproj>
<项目> {2c4b1776-3d34-4534-8520-8a1e6daa0e6e}< /项目>
<名称>&FS_PL LT; /名称>
< / ProjectReference>
< ProjectReference包括=.. \FS_PL_Legacy\FS_PL_Legacy.fsproj>
<项目> {0d7b657c-906B-4448-ae64-2153a1fa910c}< /项目>
<名称>&FS_PL_Legacy LT; /名称>
< / ProjectReference>
< /&的ItemGroup GT;

这至少可以让VS引用F#项目,但这些项目的标签发出多次警告和C#便携式库无法建立,因为它不能引用类型中的一个或两个F#库:(



大多数生成输出窗口中的警告表明,因为他们似乎有关于框架组件的间接依赖F#库不能被引用[的System.Threading / System.Lync的/ etc。]这可能不是当前目标框架内解决。


解决方案

问你们要被听到... ...




与唐赛姆和一些F#团队的微博这个问题。他们证实这是一个问题,他们认为通过释放过程工作的方式修复。



我安装的今天的Visual F#每日构建,我可以证实,这个问题已经解决了!



由于唐和F#团队解决这个问题 - 现在我可以将新的F#代码到我主要是C#代码库和放大器;测试套件......,并开始与远不如F#代码替换我们系统的大块比同等的C#;)


I have a project which contains two F# projects and a C# project in which I'd like to write some XUnit tests:

  • FS_PL: F# 3.1 (3.3.1.0) Portable Library
  • FS_PL_Legacy: F# 31. (2.3.5.1) Portable Library (Legacy)
  • Tests: C# .NET 4.5/Win8 C# Portable Class Library (PCL)

I am unable to add a reference from Tests to either of the F# libraries.

When I try to add a reference to FS_PL, I am presented with a dialog that states "Unable to add a reference to project 'FS_PL'. The targets of Portable Library project 'FS_PL' are not the same or compatible with the targets of the current Portable Library project":

This is odd since both my Tests and FS_PL libraries are configured to target .NET 4.5 & Windows 8.

So I created FS_PL_Legacy and tried adding a reference to it. Doing so gives me a very 'helpful' message stating "Unable to add a reference to project 'FS_PL_Legacy'":

Does anyone know what I am doing wrong?

Partial Workaround #1

Using miegirl's workaround from a Connect issue discussing this problem, I added the following to the C# project:

<ItemGroup>
    <!-- Manually added reference to F# projects to overcome issue discussed here:
            http://stackoverflow.com/questions/23111782/how-do-i-add-a-reference-to-f-portable-library-from-c-sharp-portable-class-libr
        -->
    <ProjectReference Include="..\FS_PL\FS_PL.fsproj">
        <Project>{2c4b1776-3d34-4534-8520-8a1e6daa0e6e}</Project>
        <Name>FS_PL</Name>
    </ProjectReference>
    <ProjectReference Include="..\FS_PL_Legacy\FS_PL_Legacy.fsproj">
        <Project>{0d7b657c-906b-4448-ae64-2153a1fa910c}</Project>
        <Name>FS_PL_Legacy</Name>
    </ProjectReference>
</ItemGroup>

This at least allows VS to reference the F# projects, but those projects are tagged with several warnings and the C# portable library is unable to build as it cannot reference the types in one or both of the F# libraries :(

Most of the warnings in the build output window indicate that the F# libraries cannot be referenced as they appear to have "an indirect dependency on the framework assembly "[System.Threading/System.Lync/etc.]" which could not be resolved in the currently targeted framework"

解决方案

Ask and ye shall be heard ...

I raised this issue on Twitter with Don Syme and some of the F# team. They confirmed that it was an issue they had a fix that was working its way through the release process.

I installed today's Visual F# daily build and I can confirm that this issue has been resolved!

Thanks to Don and the F# team for fixing this issue - I can now incorporate new F# code into my predominantly C# codebase & test suite ... and begin replacing chunks of our system with FAR less F# code than the equivalent C# ;)

这篇关于如何从C#添加到F#便携式库的引用便携式类库(PCL)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆