Solution creation
Example
I want to create a solution called KnowYourAge and then create 2 projects inside it, first one is a a razor pages app called WebApp and another project called CoreLib which is a class library, using command line interface and VS code, how do I do it?

Create solution folder
Open a terminal or command prompt window.
Create a new directory for your solution, and navigate into it:
Create a new solution file called
KnowYourAge.slnusing the .NET Core CLI:
Create a new Razor Pages app called
WebAppusing the .NET Core CLI:
This will create a new folder called WebApp with a new Razor Pages app inside it.
Add project to solution
Add the
WebAppproject to theKnowYourAgesolution:
Create a new class library project called
CoreLibusing the .NET Core CLI:
This will create a new folder called CoreLib with a new class library project inside it.
Add the
CoreLibproject to theKnowYourAgesolution:
Build the solution to make sure everything is working:
Add reference of another project
I also want to add reference of the class library on to my web application project using CLI, how do i do it?
Open a terminal or command prompt window.
Navigate to the root directory of your
WebAppproject:
Add a reference to the
CoreLibproject using the .NET Core CLI:
This will add a project reference to the CoreLib project from the WebApp project.
Save your changes and rebuild the
WebAppproject:
This will rebuild the WebApp project with the CoreLib project as a dependency.
After adding the reference, you can now use the classes and methods defined in the CoreLib project from your WebApp project!
Adding an XUnit project as well
Open a terminal or command prompt window.
Navigate to the root directory of your
KnowYourAgesolution:
Create a new xUnit test project called
CoreLibTestsusing the .NET Core CLI:
This will create a new folder called CoreLibTests with a new xUnit test project inside it.
Add the
CoreLibTestsproject to theKnowYourAgesolution:
Add a reference to the
CoreLibproject from theCoreLibTestsproject:
This will add a project reference to the CoreLib project from the CoreLibTests project.
Note
Package reference to the xunit and xunit.runner.visualstudio packages in the CoreLibTests.csproj file is added automatically, in case ther CLI did not add it, you can add it manually as shown below:
Last updated