OdeToCode IC Logo

.NET Core Opinion #2 - Managing a Repository Structure

Thursday, September 6, 2018

One of the challenges in maintaining an orderly repository structure is seeing the repository structure, at least if you are a Visual Studio user. Studio’s Solution Explorer window shows us the structure of a solution, but this presentation, which can include virtual folders, will disguise the true structure on disk, and trying to create folders and arrange files with the default Solution Explorer view is impossible.

Thus, I recommend using the command line when creating projects, folders, and files that live outside of projects. The dotnet CLI can manage Visual Studio sln files, so starting a new project might look like this:

Using the dotnet CLI to manage sln files

There are three key commands:

  1. dotnet new sln # to create a sln file
  2. dotnet new [template_name] -o [output path] # to create a project
  3. dotnet sln [sln_name] add [csproj_name] # to add a project to a solutition.

At this point, you can open the solution in Visual Studio and the files are all in the correct place. Yes, there are three commands to remember, but I find the commands easier than fighting with Studio and remembering when to uncheck the 'create solution folder' option.

If You Must Use Visual Studio

Here are two tips for those who can’t leave VS behind.

First, use the Blank Solution template in the File -> New Project dialog to get started. The Blank Solution allows you to create an empty sln file in exactly the location you need. Once the solution file is in place, you can add projects to the solution, but take care when specifying the path to the new project.

Secondly, the Solution Explorer in 2017 does have a mode where the explorer will show exactly what is on disk. You can toggle into this "Folder View" by clicking the icon in the toolbar shown in highlight below. From this view you can create folders that are real folders on disk, but you do lose some of the useful right-click context menus.

VS Folder View

With the folder structure under control, I’ll move on to other artifacts I like to see in a repository next.

Gravatar Tyler Thursday, September 6, 2018
VS engineers take note. Provide more advanced support for file structure when creating a new project and solution at the same time.
Gravatar Emmett Childess, Jr. Friday, September 7, 2018
Excellent post Scott! I see myself writing an automation script soon...real soon!
Gravatar Stephen Brouillard Monday, September 17, 2018
Scott. Thanks again. There's some great stuff in here. In the end, this is exactly the kind of content I mentioned in my comment to your first opinion post. Hopefully, as Tyler suggested, the VS engineers will take note. I imagine that maintaining backward compatibility in VS while allowing better integration with the file centric paradigm isn't exactly trivial. We'll see where it shakes out.
Gravatar Stephen Brouillard Monday, September 17, 2018
I was a little premature in posting my last comment. While I do spend the bulk of my development time in VS, I find that I often drop to the command line to work with Git, so I don't imagine it will be all that painful to drop out to the command line for the creation of new projects in an existing solution. I suppose I also need to commit to spending a bit of time in the whack-whack-terminal extension (or something similar) to get a reasonable CL interface into VS anyway.
Comments are closed.