Skip to main content

Command Palette

Search for a command to run...

Adding project dependencies in Visual Studio

Updated
1 min read
Adding project dependencies in Visual Studio
R

I am a recent graduate at the beginning of my software development career. I enjoy documenting my learnings through my blogs

I was following along a PluralSight course (Building a Real-world C# 10 Application by Filip Ekberg) when I needed to add a dependency to a project file from another project file. Intellisense would not pick up on what I wanted to add and manually typing the using statement would not work either. I needed to add a project dependency to the relevant file.

When you want to share code from one project file to another, you create a dependency. This allows the dependent project file to access code from the other project file. These dependencies could be written in the csproj file of the dependent project. See last image for an example of how this can be written.

The easiest way to carry this task out would be to drag the project file you want to reference into the dependencies of the project file that requires the dependency.

The second way to add a dependency would be to right-click on the project's dependencies and select “Add Project Reference…”.

This brings you to a screen that allows you to choose which projects you would like to add.

The project dependency can be seen under dependencies of the project under projects

or in the csproj file

<ItemGroup>
   <ProjectReference Include="..\Globomantics.Domain\Globomantics.Domain.csproj" />
</ItemGroup>