asp.net.netnuget-package

Adding reference to another project from visual studio code


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?


Solution

  • Let's say you have two projects:

    1. Project1.Api

    2. Project2.Executable


    Command line syntax for [`dotnet add reference`](https://learn.microsoft.com/en-us/dotnet/core/tools/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>
    

    Visual Studio Code documentation about project management that supports the solution: https://code.visualstudio.com/docs/csharp/project-management#_working-with-projects