You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

Rider中如何将自定义类库添加至‘Add Reference’窗口

How to Add Custom Libraries to Visual Studio's Reference Search & Bulk-Add References

Great question! Let’s break this down into two clear parts to solve your workflow pain points:

Getting Your Custom Libraries Into the Add Reference Search List

The most reliable and scalable way to make your shared libraries searchable in the Add Reference window is to use NuGet packages—here’s how:

  • First, package your class library: Right-click your class library project in Solution Explorer, select Pack, and Visual Studio will generate a .nupkg file (usually in the bin/Debug or bin/Release folder).
  • Next, add a local NuGet source: Go to Tools → NuGet Package Manager → Package Manager Settings. Under Package Sources, click the plus icon, name your source (like "Local Custom Libraries"), and point it to the folder where you saved your .nupkg files.
  • Now, when you open the Add Reference window (or use the NuGet Package Manager), you can search for your custom libraries just like any third-party NuGet package. This works across projects and machines, and you can even version your libraries easily.

If you don’t want to use NuGet, you can place your compiled DLLs into Visual Studio’s default reference assemblies folder (e.g., C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.8 for .NET Framework 4.8). Restart Visual Studio, and your libraries will show up under the Assemblies tab in Add Reference. Note: This is less flexible—versioning gets messy, and it won’t transfer to other machines.

Bulk-Adding References Quickly

If you need to add multiple references at once, these methods will save you tons of time:

  • Edit the project file directly: For SDK-style projects (default for .NET Core/.NET 5+), open your .csproj file (right-click project → Edit Project File) and add all your references in one go. Example:
    <ItemGroup>
      <!-- Add project references to your custom libraries -->
      <ProjectReference Include="..\SharedLibraries\AuthLibrary.csproj" />
      <ProjectReference Include="..\SharedLibraries\DataAccess.csproj" />
      
      <!-- Add third-party NuGet packages -->
      <PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
      <PackageReference Include="AutoMapper" Version="12.0.1" />
    </ItemGroup>
    
    Save the file, and Visual Studio will automatically load all these references.
  • Multi-select in Add Reference: Open the Add Reference window, navigate to the folder with your DLLs or projects, hold down Ctrl to select multiple items, then click OK to add them all at once.
  • Command-line bulk additions: Use the dotnet CLI to add references in bulk. For project references:
    dotnet add reference ..\SharedLibraries\AuthLibrary.csproj ..\SharedLibraries\DataAccess.csproj
    
    For NuGet packages:
    dotnet add package Newtonsoft.Json AutoMapper
    
    This is perfect if you’re automating setup or working with multiple projects.

Overall, NuGet is the best long-term solution for making your libraries discoverable, while editing the project file or using the CLI are the fastest ways to bulk-add references. Pick the approach that fits your team’s workflow!

内容的提问来源于stack exchange,提问作者Roy Zwart

火山引擎 最新活动