Create Multi Project App in .Net Core 3.0


Some time back .Net Core version 3.0 was released and I thought to explore it and then an idea came to me about creating multi project application the same way we create in .Net Framework.
.Net Core is an open source framework for developing and deploying cross platform application on any platform. Check out this link to learn more about .Net Core.
To demonstrate how we can create, build and deploy multi project app in the .Net Core 3.0, I have decided to develop a functional CVS Validator console app. I will explain the functionality of this app later.
First, we need to setup development environment.

Prerequisite

We basically need .Net CLI tools, .Net Core Runtime and a code editor in order to develop and run .Net Core app on our machine.
.Net CLI tools, .Net Core Runtime comes with the .Net Core SDK so download and install the latest version of .Net Core SDK available from this link.
And for code editor I will recommend VS Code but if you already have any other code editor that you are using to write C# code then stick with that otherwise download and install VS Code from this link .
After installing SDK and VS Code, open the command prompt and run following command to check if SDK installed properly.

dotnet --version

you must get the latest version number as a result.
After done with the environment setup we are ready to develop our CSV Validator console app.


Create Application Code Scaffolding

This app will have a solution file and three projects to contain code for client, CSV data validation functionality and unit testing.


Create Solution and Projects

So now go to the folder location where you want to develop the app and open the command window (since I have GIT installed on my machine, I will be using git bash window).
Create solution by running following command in the command window.

dotnet new sln -o CsvValidatorApp

It will create CsvValidatorApp folder with the same name solution file in it.
Now we need to create projects under this folder so move into this folder.

cd CsvValidatorApp

First, we will create console type project that will be startup Client project and entry point of our app. So run following command in the command window to create it.

dotnet new console -o CsvValidator.Client















Second one will be class library type project that will contain all the functionality for loading, validating and rendering validated csv file. So run following commands in the command window to create it.

dotnet new classlib -o CsvValidator.Data

The last one will be the nunit type project for the unit testing of class library project code that can be created by running following commands in the command window


dotnet new nunit -o CsvValidator.Test

















Once we are done with the project creation our app code structure will look like the following image.












Add Projects in the Solution

Now we need to include the projects into the solution by running following command in the command window.

dotnet sln CsvValidatorApp.sln add CsvValidator.Client/CsvValidator.Client.csproj CsvValidator.Data/CsvValidator.Data.csproj CsvValidator.Test/CsvValidator.Test.csproj










Add Project Reference


Now we need to add reference of our class library Data project in the console app Client project. For that run following command in the command window.

dotnet add CsvValidator.Client/CsvValidator.Client.csproj reference CsvValidator.Data/CsvValidator.Data.csproj

And also add reference of class library Data project in the Test project by running following command.

dotnet add CsvValidator.Test/CsvValidator.Test.csproj reference CsvValidator.Data/CsvValidator.Data.csproj











Build and Run Application


As we are done with all the scaffolding code creation we are now ready to build the app for the first time by running following command in the command window.

dotnet build CsvValidatorApp.sln

I am sure you won’t get any error since there is not much code in there.
You can run the app by running the console Client project and get the standard “Hello World” message in the command window.
Run following command to run the app.

dotnet run -p CsvValidator.Client/CsvValidator.Client.csproj

or change to CsvValidator.Client folder and run following command.

dotnet run

Start Building the App…

Now you are ready to put flash into bare bone scaffolding code of this app and for that we need to open the code editor in the application solution folder.
To open the VS Code in the folder, run following command.
code .
Get the source code of this app from my GitHub repository from this link and start adding code files and code details in your app.

About CVS Validator App

This app take the csv file and validate the data according to the validation provided to it in an xml file and generate the validated csv file at the location of the source csv file. Both files path are configured in the app configuration file. The sample of both files are in my GitHub repository along with the source code of the app. More details about the app can be found in the README.md file in the repository as well.

No comments: