Search code examples
visual-studioprojects-and-solutions

Folders or Projects in a Visual Studio Solution?


When spliting a solution in to logical layers, when is it best to use a separate project over just grouping by a folder?


Solution

  • By default, always just create new folder within the same project

    • You will get single assembly (without additional ILMerge gymnastic)
    • Easier to obfuscate (because you will have less public types and methods, ideally none at all)

    Separating your source code into multiple projects makes only sense if you...

    • Have some portions of the source code that are part of the project but not deployable by default or at all (unit tests, extra plugins etc.)
    • More developers involved and you want to treat their work as consumable black box. (not very recommended)
    • If you can clearly separate your project into isolated layers/modules and you want to make sure that they can't cross-consume internal members. (also not recommended because you will need to decide which aspect is the most important)

    If you think that some portions of your source code could be reusable, still don't create it as a new project. Just wait until you will really want to reuse it in another solution and isolate it out of original project as needed. Programming is not a lego, reusing is usually very difficult and often won't happen as planned.