Hello all! Before you begin reading, keep in mind that this tutorial is designed for beginners. As such, it covers every step without skipping parts that might be obvious to some. This tutorial is made possible thanks to Josh Kostal, who taught me majority of what is covered in this post.
The reason you have to undergo such a tedious process to create the initial folder structure is because simply creating folders in the File Explorer will not be mirrored inside the Visual Studio. We also have to manually reconfigure the new path to the .csproj file after moving the application over to the new folder. You will see what I mean as we move forward in this tutorial!
Part 1 of this tutorial series covers the initial stage of the setup as described in the overview below.
Part 2 will include publishing the data in the tables to your local machine, reverse engineering to create the dbcontext, and adding other components such as providers and models in ’02 – Application’ and ’03 – Domain’ folders.
Overview of Part 1
- Create ASP.NET Web Application (.NET Framework).
- Create the folder structure in the File Explorer (01 – Presentation, 02 – Application, 03 – Domain, and 04 – Database).
- Transfer the application created in 1) to “01 – Presentation” folder.
- Reconfigure the path for .csproj file.
- Go into Visual Studio and create the Solution Folders that align with the folder structure in the File Explorer.
- Drag the original project into the “01 – Presentation” solution folder inside the Visual Studio.
- Create Sql server database project and configure the path to the “04 – Database” folder.
- Make adjustments in Visual Studio accordingly.
- Add scripts and table files.
Creating the Folder Structure
1) Create a new ASP.NET Web Application (.NET Framework) using the MVC template. I will name the application ‘Demo_01’ in this example.
2) Once you create the project, go to where the project is located in the File Explorer. Inside the folder that contains the .sln file, create folders that will each hold the ‘Presentation’, ‘Application’, ‘Domain’, and ‘Database’ component.
3) Drag all the items in the application folder (source > repos > Demo_01 > Demo_01 in this example) into the “01 – Presentation” folder. The image below demonstrates all the items that were dragged and dropped (or copied and pasted) into the new folder.
4) Open .sln file with a Notepad++ (Notepad works too).
5) Edit the path for .csproj file (now that you have moved the .csproj file from the original application folder to the “01 – Presentation” folder). You can change where it is highlighted in the image below.
However, when you open up the .sln file, you are going to realize how the folders you created in the File Explorer are not reflected within Visual Studio. You will have to create solution folders separately inside Visual Studio.
6) Right click the solution file and add a New Solution Folder (Note how it is NOT a regular New Folder).
7) Drag the project into the “01 – Presentation” folder and create other solution folders accordingly.
Adding the Database Project
8) Create a new SQL Server Database Project. This is the database where the schema and the scripts will go.
9) Name your project and configure the path to the “04 – Database” folder we created earlier. I will name it ‘Demo_01.Database’ in this example.
Demo_01.Database project will open up but simply close it and go back to the original Demo_01.sln file. However, you will notice that the .Database project you just created is not visible in the solution.
10) Right click the solution and Add Existing Project. Locate the SQL server database project you created in 8) and click ‘Open’.
11) Drag .sqlproj file you just open in 10) into “04 – Database” folder and right click that file (not the “04 – Database” folder) to create sub-folders called “Tables” and “Scripts”. Right click the Tables folder to Add a Table and the Scripts folder to Add a Script (Not in build). Table is where the columns will be defined and scripts where the data will be seeded. Refer to the images below.
12) Add a Post deployment script file under Scripts folder as well. Post deployment script will run once the tables are deployed. This script includes simple commands to allow each of the seed scripts to run and you NEED this.
Below are examples of how each of the three files would look like.
Script file is empty the first time you publish. This is how the script would appear when you need to seed data afterwards.
That is it for the initial setup! In part 2, we will cover publishing the data to your local machine, reverse engineering to create the dbcontext, and adding other components such as providers and models in ’02 – Application’ and ’03 – Domain’ folders.