32

In most .NET project I can use folder to organise the code files. In C++, I can't, but filters end up playing the same role. However, in F# with Visual Studio 2010, I can't. Every code file is shown directly in the project dir. Why is this feature not available?

And what is the optimal strategy for organizing a project with a lot of files?

Laurent Bourgault-Roy
  • 2,774
  • 1
  • 30
  • 36
  • This question was being linked to from [this uservoice](https://visualstudio.uservoice.com/forums/121579-visual-studio-2015/suggestions/6077963-add-folders-for-visual-f-projects). Now go vote! – Christoffer Lette Feb 22 '16 at 21:33

2 Answers2

36

Actually, you can add folders to F# projects but it's not supported directly through Visual Studio (you have to edit the project file yourself): http://fsprojectextender.codeplex.com/ (edit: old link was broken, updated to F# Project Extender home page which has links to the original blog posts which were moved) (which I found in this answer).

I do this myself, but it is cumbersome and you end up avoiding it until keeping sanity really demands it. I think the feature simply slipped, or perhaps there wasn't as much a culture for folder organization with the F# designers in the first place. You can see in the F# source code that they favor huge source files with no directories, with separate projects as an organization boundary.

I imagine the F# project template could be modified to support this, and it is certainly something I'd like to see happen. At the same time the linear compilation order F# enforces causes your code to be somewhat self-organized, and so folder grouping plays a less significant role.

Community
  • 1
  • 1
Stephen Swensen
  • 22,107
  • 9
  • 81
  • 136
13

Manually editing the .fsproj file as described in Stephen's answer is one option (and I used it when I wanted to organize one larger project).

However, you have to be a bit careful and I think you cannot add new files to the folders (creating a file by hand and then adding an existing file works). However, if you like to keep things organized (like I do), then it should work for you.

Additionally, there is also a tool called F# Project Extender that should make things a bit easier for you . I have not tried it yet, but it looks like it supports adding folders (and perhaps other useful things). See for example this blog post by the project author.

dplante
  • 2,445
  • 3
  • 21
  • 27
Tomas Petricek
  • 240,744
  • 19
  • 378
  • 553
  • Hmm, I was thinking driving compilation order using a pre-order traversal of the file / directory structure you layout through the project explorer would be the way to go (I think I'd get a bit confused with alphabetic ordering in F# Project Extender). – Stephen Swensen May 07 '11 at 02:46
  • I'd like to mark both reply as the answer as you both answer a different facet of my question, but I don't think I can, so I'll just say thank you ^^ – Laurent Bourgault-Roy May 09 '11 at 19:14