You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

多应用能否引用包含其他项目引用的全局统一项目?

Is Creating a "Libs" Aggregator Project Feasible for Simplifying Project References?

Absolutely, this approach works perfectly—you just need to fix a few configuration gaps causing the missing assembly errors, and we can even streamline that tedious "add existing project" step. Let’s break this down:

Step 1: Set Up the Libs Project Correctly

First, create a new Class Library project named Libs in your application’s solution. Then add all 5 source projects to the solution (we’ll make this less tedious later). The critical details here:

  • Add Project References from Libs to each of the 5 source projects (don’t reference their compiled DLLs directly). This ensures the build system tracks dependencies end-to-end.
  • Double-check that all projects (your app, Libs, and the 5 sources) target the same .NET framework version—mismatched frameworks are a top cause of missing assembly errors.

Step 2: Fix the Missing Assembly Errors

The "missing assemblies" issue happens because the source project DLLs aren’t being copied to your application’s output directory. Here’s how to resolve it:

  • In the Libs project, expand the References list, right-click each source project reference, and select Properties.
  • Set the Copy Local property to True. This tells MSBuild to copy the source project’s DLL (and any its own dependencies) to Libs’ output folder during build. Since your app references Libs, these DLLs will then be copied to your app’s output directory automatically.
  • If any source projects have NuGet dependencies, confirm those packages are marked as transitive (this is the default for NuGet, so you likely won’t need changes—just ensure the packages are installed in either the source projects or Libs itself).

Step 3: Streamline the "Add Existing Project" Process

Manually adding 5 projects to every new app solution is a hassle, so here are two ways to simplify this:

Option A: Use a Directory.Build.props File

Create a Directory.Build.props file in the root of your application’s solution folder, and add paths to all 5 source projects like this:

<Project>
  <ItemGroup>
    <ProjectReference Include="..\..\SourceProjects\Project1\Project1.csproj" />
    <ProjectReference Include="..\..\SourceProjects\Project2\Project2.csproj" />
    <!-- Add the other 3 source projects here with their correct relative paths -->
  </ItemGroup>
</Project>

Now, whenever you open the solution, MSBuild will automatically load all these source projects—no manual adding required. Your Libs project can then reference them directly from the solution.

Option B: Package Source Projects as NuGet Packages

If you reuse these 5 source projects across many solutions, package each as a NuGet package (host them in a private feed if needed). Then, instead of adding source projects to your app’s solution, Libs can reference these NuGet packages. This eliminates the "add existing project" step entirely, and NuGet handles dependency copying automatically.

Final Quick Checks

  • Rebuild the entire solution after making changes to ensure all dependencies are copied correctly.
  • Verify your app’s output directory—you should see Libs.dll alongside all 5 source project DLLs and their dependencies.

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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.13 08:19:20