Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating and referencing class libraries with dotnet CLI and VSCode just like you can do in Visual Studio

I want to start using vscode to develop .net core apps, but I am a bit confused about how to create class libraries as separate projects and reference them.

For example: In a Visual Studio Solution I would add a Web API project and then several class libraries to that solution. Right click the Web API project and Add Reference as necessary.

Can this same thing be done with VS Code and dotnet CLI even though there is no solution concept?

like image 218
Blake Rivell Avatar asked Oct 16 '25 06:10

Blake Rivell


1 Answers

Create Solution Folder

c:\Projects>mkdir SampleDotNet
c:\Projects>cd SampleDotNet

Create SampleDotNet solution

c:\Projects\SampleDotNet>dotnet new sln

Create src folder (optional)

c:\Projects\SampleDotNet>mkdir src 

c:\Projects\SampleDotNet>cd src

Create Web API Project

c:\Projects\SampleDotNet\src>dotnet new webapi -n SampleDotNet.Api

Create Class Library Project

c:\Projects\SampleDotNet\src>dotnet new classlib -n SampleDotNet.Services

Reference Library Project to Web API Project

c:\Projects\SampleDotNet\src>dotnet add SampleDotNet.Api/SampleDotNet.Api.csproj reference SampleDotNet.Services/SampleDotNet.Services.csproj

Finally Add Projects to Solution

c:\Projects\SampleDotNet\src>cd ..
c:\Projects\SampleDotNet>dotnet sln add src/SampleDotNet.Api/SampleDotNet.Api.csproj
c:\Projects\SampleDotNet>dotnet sln add src/SampleDotNet.Services/SampleDotNet.Services.csproj

Commands

enter image description here

Result

Visual Studio Code

enter image description here

Visual Studio

enter image description here

like image 92
Win Avatar answered Oct 17 '25 19:10

Win



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!