Adding reference to another project from visual studio code

You can open .csproj file of the project you want to add reference to and add project reference like this:

<ItemGroup>
    <ProjectReference Include = "<RELATIVE_PATH_TO_REFERENCE_PROJECT>" />
</ItemGroup>

If the ItemGroup for ProjectReference already exist then you can just add to it.

Example:

<ItemGroup>
    <ProjectReference Include = "../MyLibrary.csproj" />
</ItemGroup>

Add "vscode-solution-explorer" Extension. It will folder structure as visual studio. Right click on project --> Add Reference --> Select the reference project from the list.


Let's say you have two projects:

1) Project1.Api

2) Project2.Executable


Command line syntax for dotnet add reference:

    cd Project2.Executable
    dotnet add reference ../Project1.Api/Project1.Api.csproj

If you check the Project2.Executable.csproj file, you will see the following entry:

    <ItemGroup>
         <ProjectReference Include = "..\Project1.Api\Project1.Api.csproj" />
    </ItemGroup>