29

We had a contractor visit recently who questioned our methodology of structuring projects. Please note that I am specifically referring to the directory structure. He suggested using the Microsoft guidelines. I thought I would be able to Google "Microsoft guidelines .NET project directory structure" and find something helpful, however this has proven not to be the case. As it stands we do something like this:

[Company.System.Feature]
  |-doc
     |Sandcastle project
  |-lib
     |Nuget packages
  |-src
    |-Project1 e.g. web
    |-Project2 e.g. business logic
    |-UnittestProject1
    |-Specs

The doc folder contains a Sandcastle solution like what is described here: https://www.codeproject.com/Articles/15176/Sandcastle-Help-File-Builder (see: absolute and relative paths). Therefore the doc folder contains a Help folder, which contains the generated help file. The lib folder contains all Nuget packages.

Are there any Microsoft guidelines, which recommend how to structure a solution? I have looked here: https://stackoverflow.com/questions/789389/project-structure-for-c-sharp-development-effort/789554?noredirect=1#comment86756309_789554 amongst other places. Most of the articles and questions I have read seem to be created 2007-2009. I believe Nuget was introduced in 2010. Are there any Microsoft guidelines? I read about something called Tree Surgeon, however this does not seem to exist anymore: https://archive.codeplex.com/?p=treesurgeon.

I am using TFS; Cruise Control and DDD is that makes any difference.

w0051977
  • 7,031
  • 6
  • 59
  • 87
  • 5
    Directory structures are very much a matter of taste. Use the folder structure that most clearly states your project/organizations intentions. – Robert Harvey Apr 17 '18 at 14:49
  • 6
    Also, the next time someone says you should be following "Microsoft Guidelines" about something, ask said person to provide those guidelines, or show you where you can find them. Otherwise, it's useless advice. – Robert Harvey Apr 17 '18 at 14:51
  • 3
    the odd bit is putting nuget packages in lib instead of packages – Ewan Apr 17 '18 at 15:23
  • 1
    @Ewan, nuget packages don't even belong in `packages` any more, for dotnetcore and VS2017-style projects. They now live in the projects' `obj` directories. – David Arno Apr 17 '18 at 15:58
  • ... checks vs2017 project in front of him... hmmm packages – Ewan Apr 17 '18 at 16:00
  • @Ewan, [you did upgrade to the csproj format though, right?](https://www.natemcmaster.com/blog/2017/03/09/vs2015-to-vs2017-upgrade/) :) – David Arno Apr 17 '18 at 16:06
  • 2
    pff! upgrading?!?!? sounds like it might break stuff – Ewan Apr 17 '18 at 16:08
  • I just checked a new project though and its also got packages. are you sure its not just the .net core / standard stuff? – Ewan Apr 17 '18 at 16:09
  • hmm I just made a .net standard library and its putting the packages in a hidden .nuget folder in my user folder – Ewan Apr 17 '18 at 16:19
  • @David Arno, are you saying that the information in your link is wrong? I guess the Nuget packages folder can be relocated from obj? Is that normal? – w0051977 Apr 17 '18 at 16:30
  • No, I'm saying that a solution using VS2017-style csproj files doesn't need the `packages` folder as MSBuild stores them in the projects' `obj` directories. But, if you don't have such a solution, then that `packages` directory is still used. – David Arno Apr 17 '18 at 16:35
  • @David Arno, I believe a .NET Framework project uses the packages folder and a .NET Standard/.NET Core project uses the obj folder. Can you confirm that is what you mean by a VS2017-style project? Thanks. – w0051977 Apr 17 '18 at 16:45
  • @w0051977, take a look at [colorToolPlus](https://github.com/DavidArno/colorToolPlus), a personal project of mine. If you look in eg [ColorToolPlusTests.csproj](https://github.com/DavidArno/colorToolPlus/blob/master/ColorToolPlusTests/ColorToolPlusTests.csproj), you'll see it references .NET 4.7 (ie it's a framework project) and it references nuget. But there's no `packages` folder in this solution. That's what I mean by "VS2017-style" projects. – David Arno Apr 17 '18 at 17:50
  • @David Arno, I think Ewan is right - the Nuget packages are stored in: C:\Users\.nuget. I wander why? I wander if it is because there are two many packages required for .NET Core/.NET Standard and it is more efficient to store them all in one place? – w0051977 Apr 18 '18 at 09:20
  • @Ewan, please see comment above. – w0051977 Apr 18 '18 at 09:20
  • im not so much right as testing – Ewan Apr 18 '18 at 09:29
  • `%UserProfile%\.nuget\packages` is one of the caches used by nuget. Have a read of https://docs.microsoft.com/en-us/nuget/consume-packages/managing-the-global-packages-and-cache-folders for more details. – David Arno Apr 18 '18 at 09:41
  • @David Arno, ,would you say that your answer is more specific to .NET Framework project where the packages folder is stored locally. Alternatively is the Microsoft Developer advocating moving the packages folder to the solution folder for .NET Standard and .NET Core? Thanks. – w0051977 Apr 18 '18 at 12:11

1 Answers1

31

On MSDN, there are some very old official guidelines. These are out of date though. As the page says, "This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies." So I'd recommend you avoid these guidelines.

There was an attempt to define a common solution structure via Project Scaffold. This is more orientated toward F# though, rather than C#. It didn't really take off though and there's little sign of development of the ideas these days.

The most active and up to date set of guidelines is maintained by David Fowler, who is a developer at Microsoft on the ASP.NET team. These guidelines are used by many within Microsoft, including the Roslyn (the C# and VB.Net compiler) teams. You could do far worse than adopt that approach therefore.

David Arno
  • 38,972
  • 9
  • 88
  • 121
  • I saw the first two links, but not the third. +1 for the third link. Would I put my entire Sandcastle project in the docs folder or just the Help files that are generated by the Sandcastle project? Not sure why this answer was downvoted. – w0051977 Apr 17 '18 at 14:14
  • 1
    To be fair, every page that isn't included in Microsoft's new documentation system is stamped with the words "this content is outdated and no longer being maintained." That doesn't mean there isn't some useful information there. – Robert Harvey Apr 17 '18 at 14:53
  • Were would you put the Specs? In the Tests folder or in a directory called Specs (in the same directory as the src folder)? I guess it doesn't really matter too much. – w0051977 Apr 22 '18 at 13:57
  • @RobertHarvey: Fair enough, but referring to that page alone with nothing further to back it up is also not a reason to change the project folder structure if a different one has already been established. – Flater May 07 '18 at 13:30
  • 3
    You can see David Fowlers guidelines in practice at most of the open source projects at GitHub, eg [Enity Framework](https://github.com/aspnet/EntityFrameworkCore). – pfx May 26 '18 at 16:14