Adding reference to another project from visual studio code

user6728767 picture user6728767 · Apr 12, 2018 · Viewed 21.9k times · Source

If a library (eg, on github) doesn't distribute itself via a nuget package, I'd have to manually include it as a reference, correct? I see a lot of reference posts for how to add a reference to a project for Visual Studio, but I can't seem to figure out how to do it on Visual Studio Code.

In this case, I've downloaded the library's zip, and moved the expanded folder into my project, and then tried using <namespace>, which did not work.

EDIT:

I noticed that this downloaded zip contained a .nuspec. Is there something I can do with this file extension to import it in my project?

Answer

Jos&#233; Am&#237;lcar Casimiro picture José Amílcar Casimiro · Jun 10, 2018

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>