Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to bypass Visual Studio's F# project folder limitations on Xamarin.Android?

I've created a new Xamarin.Android app and added a few assets to it. Those assets are available in multiple resolutions, so I placed them in their respective drawable-XXXfolders inside the Resources folder. Doing so resulted in the following error:

The project 'XXXX.fsproj' could not be opened because opening it would cause a folder to be rendered multiple times in the solution explorer. One such problematic item is 'Resource\drawable-hdpi\pencil.png'

This is being caused by F#'s poor folder structure handling. I usually don't need to use folders at all in F# projects, but in this specific case it's necessary because of the way Android deals with resources. The project loads fine in Xamarin Studio, but in Visual Studio it doesn't.

The project is quite big, what means I (and other people as well) will need to add a lot of files, so manual approaches like this one are of no use, for they're too time consuming.

I read the official docs but there's nothing there that states there's a special way to handle adding files on VS or another way to deal with this limitation. My question is: such thing exists? Can I add those files in another way so that I don't need the complex structure on VS? Will I be forced to use C# or Xamarin Studio against my will?

like image 649
William Barbosa Avatar asked Sep 14 '15 02:09

William Barbosa


2 Answers

The references to folder files have to be listed together, they can not be interspersed with files in different location. Sort the refs and it will be fine.

EDIT, for clarity:

<ItemGroup>
<Compile Include="folder\file1.fs" />
<Compile Include="file.fs" /> <-- this can't be between the folder files, all folder files have to be listed together
<Compile Include="folder\file2.fs" />
</ItemGroup>
like image 152
Eugene Tolmachev Avatar answered Sep 16 '22 17:09

Eugene Tolmachev


Sadly, the standard Visual Studio integration does not support folders in F# projects.

Your best option is to use the Visual F# PowerTools. This adds some support for folders to F# projects and so it may work good enough to do what you need. If it does not, then Visual F# PowerTools is an open-source project and it always welcomes contributions!

I don't know much about the Xamarin Android project types - but I guess that adding C# project which is just an empty DLL to store the resources would be a reasonable alternative too. (Then you should be able to reference this from F# and load all resources from there.)

like image 43
Tomas Petricek Avatar answered Sep 20 '22 17:09

Tomas Petricek