Online courses in ASP.NET MVC / Core, jQuery, Angular, and Design Patterns conducted by Bipin Joshi. Read more...
Learn ASP.NET MVC / Core, jQuery, Angular, and Design Patterns through our online training programs. Courses conducted by Bipin Joshi on weekends. Read more details here.

ASP.NET Core - Old Solution Structure Vs. New Solution Structure

Recently one of the readers, who was quite new to ASP.NET Core, asked this question -

"I am following your instructions to create a working example based on your article. After creating the project my solution explorer looks different than your screen shots. Why is so? Am I missing something?"

Well. That's actually because of a simple setting. But it is always good to know why things are happening in the way they are. So, in this short post I am explaining why you see two different solution structures in Visual Studio 2015.

Solution Structure - ASP.NET MVC 5 Style

Let's create a new ASP.NET MVC 5 project using Visual Studio 2015.

Open Visual Studio 2015 and select File > New > Project. This will open a new project dialog as shown below:

Observe this dialog carefully. Specifically note the following:

  • Project name is Project1
  • Solution name is Solution1
  • Create directory for solution checkbox is checked

When you complete the project creation your Solution Explorer will resemble this:

If you glance over the folder structure using Windows explorer, you will have this:

Notice that under the Demos folder you have Solution1 folder because you selected the "Create directory for solution" checkbox. Inside, you have Project1 folder that contains all the project specific files and folders.

Now, create a new project again but this time uncheck the "Create directory for solution" checkbox.

This time Project2 folder (the folder containing project's files and folders) gets created directly inside Demos folder. There is no separate folder for solution since you unchecked the "Create directory for solution" checkbox.

Solution Structure - ASP.NET Core Style

So far so good. Now create a new ASP.NET Core project by checking the "Create directory for solution" checkbox.

This time project name is Project3 and solution name is Solution3. This time your solution explorer would look like this:

That's bit different! Observe the following differences:

  • There are two top level folders - Solution Items and src.
  • Solution Items contains global.json file.
  • Src folder contains the project - Project3.

Now try adding another project to the same solution by right clicking on Solution3 (this process remains the same as before). After adding the new project your Solution Explorer will resemble this:

Thus all the projects belonging to a solution are located inside the Src folder. The physical folder structure will look like this:

You may ask - Why this structure?

That's because this structure closely resembles the GitHub project layout. Since ASP.NET Core heavily uses OSS, the new solution structure mimics what people using repositories such as GitHub are familiar with.

You are not limited to these two folders. You can, for example, create Tests folder to store unit testing related things and Documentation folder to store documentation files.

Now you may ask - Can I continue using the older solution structure in ASP.NET Core also?

Yes. You can do that. Simply uncheck the "Create directory for solution" checkbox while creating a project and you will have a solution with older and familiar structure. Here is an example:

And  the result is as follows:

That's it for now! Keep coding !! 

Bipin Joshi is a software consultant, trainer, author and a yogi having 21+ years of experience in software development. He conducts online courses in ASP.NET MVC / Core, jQuery, AngularJS, and Design Patterns. He is a published author and has authored or co-authored books for Apress and Wrox press. Having embraced Yoga way of life he also teaches Ajapa Meditation to interested individuals. To know more about him click here.

Get connected : Twitter  Facebook  Google+  LinkedIn

Posted On : 06 Dec 2016

Tags : ASP.NET ASP.NET Core .NET Framework Visual Studio