dotnet-add referencedotnet-add reference

本文適用於:✓ .NET Core 1.x SDK 及更新版本This article applies to: ✓ .NET Core 1.x SDK and later versions


dotnet add reference - 新增專案對專案 (P2P) 參考。dotnet add reference - Adds project-to-project (P2P) references.


dotnet add [<PROJECT>] reference [-f|--framework] <PROJECT_REFERENCES> [-h|--help]


dotnet add reference 命令提供方便的選項,將專案參考新增至專案。The dotnet add reference command provides a convenient option to add project references to a project. 執行命令之後,系統就會將 <ProjectReference> 元素新增至專案檔。After running the command, the <ProjectReference> elements are added to the project file.

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



    指定專案檔。Specifies the project file. 如果未指定,命令會在目前的目錄中搜尋一個專案檔。If not specified, the command searches the current directory for one.


    要新增的專案對專案 (P2P) 參考。Project-to-project (P2P) references to add. 指定一個或多個專案。Specify one or more projects. Unix/Linux 系統支援 Glob 模式 (英文)Glob patterns are supported on Unix/Linux-based systems.


  • -h|--help

    印出命令的簡短說明。Prints out a short help for the command.

  • -f|--framework <FRAMEWORK>

    只有在以特定架構為目標時,才能新增專案參考。Adds project references only when targeting a specific framework.


  • 新增專案參考:Add a project reference:

    dotnet add app/app.csproj reference lib/lib.csproj
  • 新增目前目錄中專案的多個專案參考:Add multiple project references to the project in the current directory:

    dotnet add reference lib1/lib1.csproj lib2/lib2.csproj
  • 在 Linux/Unix 上使用 Glob 模式新增多個專案參考:Add multiple project references using a globbing pattern on Linux/Unix:

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