How to Add Multiple Projects in Visual Studio Code

Visual Studio Code Supports Multiple .NET Core Projects with This Simple Trick

Published on July 12, 2017

Adding multiple .NET projects in Visual Studio Code is a breeze. Not many people are aware that VS Code supports multiple projects.

Visual Studio Code doesn't support solution files, whereas Visual Studio does. In Visual Studio we use solution files to link multiple projects together, and at first I thought that this was going to be a deal breaker for Visual Studio Code - but it's not at all. Many people aren't aware that Visual Studio Code, although lightweight, is a powerful editor that can do most of the things you need.

Even though Visual Studio Code was probably meant as a directory based editor where you only work with files in a single directory, and many people only use it in this way, Visual Studio Code does support multiple projects. Visual Studio Code doesn't have the ability to add multiple projects via the menu items, but it can be done very easily and with minimal effort. Read along to see exactly how you can add multiple projects in Visual Studio Code.

How To Use Multiple Projects with Visual Studio Code

Using multiple projects with VS Code is quick and easy to do.

Yes, Visual Studio Code doesn't support .sln files, but you can add project references between projects. This way, you maintain separate projects and each project is compiled separately, just like it works in Visual Studio.

Let me show you how it works.

Step 1

Create a new directory that will house all your projects. Think of this as your solution directory.

mkdir vs-code-multiple-projects

Step 2

Change into the directory, and create your first project with .NET Core's CLI tooling.

cd vs-code-multiple-projects
dotnet new mvc -o HumanKode.Web

Step 3

Now, create the second project.

dotnet new classlib -o HumanKode.Extensions

Step 4

Open your project and add a reference. Change into the directory of the project to which you want to add a reference.
In this instance, I want to add a reference to the class library project in my web project, so I'm going to change into the web project directory and run the add reference command from the web directory which will add a reference to the class library project. 

cd HumanKode.Web
dotnet add reference ../HumanKode.Extensions/HumanKode.Extensions.csproj


If you view the web csproj file, you will see a reference was added.


    <ProjectReference Include="..\HumanKode.Extensions\HumanKode.Extensions.csproj" />



Using this method, you can add as many projects as you want.
Since using this method, I've started converting more of my older Visual Studio projects to Visual Studio Code projects using .NET core.

If you liked this post, stay tuned for the upcoming follow-up post where I'll show you how you can use Visual Studio Code with Entity Framework Core in a separate project.