Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I add a reference to F# Portable Library from C# Portable Class Library (PCL)

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": enter image description here

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'": enter image description here

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"

like image 397
Rich Turner Avatar asked Apr 16 '14 14:04

Rich Turner


People also ask

How do I manually add a reference?

Select “References” and then “New Reference”, or press “Ctrl+N” on your keyboard or click the “New Reference” button (a clipboard with a plus sign). Choose the appropriate reference type from the “Reference Type” drop-down menu.

How do I insert a reference list in word?

Click where you want to insert the bibliography—usually at the end of the document. Click the Reference tab. Then, click Bibliography in the Citations &amp; Bibliography group. From the resulting dropdown list, choose a bibliography.


1 Answers

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# ;)

like image 52
Rich Turner Avatar answered Sep 25 '22 17:09

Rich Turner