Rider中如何将自定义类库添加至‘Add Reference’窗口
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
.nupkgfile (usually in thebin/Debugorbin/Releasefolder). - 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
.nupkgfiles. - 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
.csprojfile (right-click project → Edit Project File) and add all your references in one go. Example:
Save the file, and Visual Studio will automatically load all these references.<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> - Multi-select in Add Reference: Open the Add Reference window, navigate to the folder with your DLLs or projects, hold down
Ctrlto select multiple items, then click OK to add them all at once. - Command-line bulk additions: Use the
dotnetCLI to add references in bulk. For project references:
For NuGet packages:dotnet add reference ..\SharedLibraries\AuthLibrary.csproj ..\SharedLibraries\DataAccess.csproj
This is perfect if you’re automating setup or working with multiple projects.dotnet add package Newtonsoft.Json AutoMapper
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




