Search code examples
c#gitvisual-studiorepo

In Visual Studio, when working on a project with more than one repository, how do I make the repo A acknowledge the repo B?


I have repo A and repo B, they're in different folders, but repo A uses a namespace from repo B, how would I make this connection in Visual Studio 2022? Is there a way, other than including all files in the same project?


Solution

  • First, you need to include the project (.csproj) from repo B in the Solution (.sln) of repo A. Then, in the project from repo A, you need to add a project reference to project B.

    To do this, follow these steps:

    1. In the Solution that contains the project from repo A, right click on the Solution and choose Add --> Existing Project
    2. Navigate to the folder where your .csproj of repo B exists and select the .csproj, then hit OK
    3. In your Solution, in project A right click on Dependencies and select "Add Project Reference"
    4. Select project B

    Now, your project from repo A references the project from repo B and can use its APIs.

    That's the simple way. The drawback is that this will only work locally, because it depends on the folder setup and the relative paths of the projects from the different repos.

    You could also try submodules if you work with Git as described here: Add git submodule as reference to existing solution in VS