Skip to content

Latest commit

 

History

History
95 lines (63 loc) · 2.83 KB

File metadata and controls

95 lines (63 loc) · 2.83 KB
title dotnet reference add command
description The dotnet reference add command provides a convenient option to add project-to-project references.
ms.date 10/28/2025

dotnet reference add

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

Name

dotnet reference add - Adds project-to-project (P2P) references.

Note

If you're using .NET 9 SDK or earlier, use the "verb first" form (dotnet add reference) instead. The "noun first" form was introduced in .NET 10. For more information, see More consistent command order.

Synopsis

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

dotnet reference add -h|--help

Description

The dotnet reference add 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" />
  <ProjectReference Include="..\lib3\lib3.fsproj" />
</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

  • PROJECT

    Specifies the project file. If not specified, the command searches the current directory for one.

  • PROJECT_REFERENCES

    Project-to-project (P2P) references to add. Specify one or more projects. Glob patterns are supported on Unix/Linux-based systems.

Options

  • -f|--framework <FRAMEWORK>

    Adds project references only when targeting a specific framework using the TFM format.

  • [!INCLUDE help]

  • [!INCLUDE interactive]

Examples

  • Add a project reference:

    dotnet reference add lib/lib.csproj --project app/app.csproj
    
  • Add a compatible .NET language (for example, F#) project reference, which works in both directions:

    dotnet add app/app.csproj reference lib/lib.fsproj
    
  • Add multiple project references to the project in the current directory:

    dotnet reference add lib1/lib1.csproj lib2/lib2.csproj
    
  • Add multiple project references using a globbing pattern on Linux/Unix:

    dotnet reference add **/*.csproj --project app/app.csproj