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

雨燕双飞 提交于 2019-12-04 23:07:52

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

This bug is old, but still occurs. I ran into this issue when running VS 2015 Community. I realize that this question is about VS 2013, but I was not sure else where to post my answer.

I had a Xamarin Forms Xaml app and I wanted to add an F# PCL to do some calculations. I saw the warning message when trying to reference the F# PCL in my C# PCL:

Unable to add a reference to 'PortableLibrary1'. Portable Library projects can only reference other Portable Library projects and assemblies.

I tried editing the csproj file directly and even tried upgrading to VS 2017 RC but nothing was working.

The fix is a bit of a hack.

  1. First build everything (including the Portable F# project)
  2. Add the F# reference to the C# project by browsing to the output DLL. i.e. Right Click on CS Project, Add -> Reference... -> Browse -> Click "Browse..." button and select the F# project DLL (mine was in my debug folder), then click OK.
  3. The F# PCL now shows in the references list in solution explorer.
  4. Add the F# project reference to the C# project again but by selecting the project i.e. Right Click on CS Project, Add -> Reference... -> Projects -> Check the PortableLibrary project and click OK.
  5. This gives me no error message box about adding the reference, and I can get to all my F# goodness in my C# project.

I don't know the root cause, but you can manually edit the .csproj file to add a reference to the F# project. It will show a warning in the solution explorer indicating that something's still wrong, but it seems to work in practice.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!