Adding reference to another project from visual studio code

后端 未结 4 1988
孤独总比滥情好
孤独总比滥情好 2020-12-28 16:12

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

相关标签:
4条回答
  • 2020-12-28 16:44

    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>
    
    0 讨论(0)
  • 2020-12-28 16:48

    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.

    0 讨论(0)
  • 2020-12-28 16:56

    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>
    
    0 讨论(0)
  • 2020-12-28 17:02

    In visual studio, in the solution explorer, expand the project that will reference this other library. You will see "References", right click and choose "Add". Then choose browse on the left. Find your dll in your file system. If vs can't find the library you may need to unzip it. I've read where you may need to copy the dll into the bin folders, I recommend trying it without doing that, then copying it in to them if it fails without them.

    Btw Googling "visual studio add reference" comes up with A LOT of great results.

    0 讨论(0)
提交回复
热议问题