dotnet-add-reference - Man Page

Adds project-to-project (P2P) references.

Examples (TL;DR)

dotnet add reference

This article applies to: ✔️ .NET Core 3.1 SDK and later versions

Synopsis

dotnet add [<PROJECT>] reference [-f|--framework <FRAMEWORK>]
     [--interactive] <PROJECT_REFERENCES>

dotnet add reference -h|--help

Description

The dotnet add reference command provides a convenient option to add project references to a project. After running the command, the <ProjectReference> elements are added to the project file.

<ItemGroup>
  <ProjectReference Include="app.csproj" />
  <ProjectReference Include="..\lib2\lib2.csproj" />
  <ProjectReference Include="..\lib1\lib1.csproj" />
</ItemGroup>

Add a reference to an assembly that isn’t in a project

There’s no CLI command to add a reference to an assembly that isn’t in a project or a package. But you can do that by editing your .csproj file and adding markup similar to the following example:

<ItemGroup>
  <Reference Include="MyAssembly">
    <HintPath>.\MyDLLFolder\MyAssembly.dll</HintPath>
  </Reference>
</ItemGroup>

Arguments

Options

Examples

Info

2024-10-02 .NET Documentation