Mr. Boy
Mr. Boy

Reputation: 63738

Can I add a project dependency to a project not in my solution?

I've created a utility library project which is required by an application project

Unless I add it to the same solution, the only way I can see to create the dependency reference in VS2022 is by pointing at the DLL/EXE assembly on disk in the Reference Manager -> Browse window.

But now I have to explicitly pick the debug/release file and that doesn't seem correct. Do I simply have to have them in the same solution or is there another mechanism to describe project-level dependencies instead of assembly dependencies (I assume config files of some type)?

Upvotes: 0

Views: 1564

Answers (1)

Jimmy
Jimmy

Reputation: 28396

You can add a project reference in the project file even if it points to a project that isn't in the solution:

<ItemGroup>
  <ProjectReference Include="path/to/UtilityProject.csproj" />
</ItemGroup>

There may be some features in the IDE that don't behave as expected when the project is not included in the solution, though I can't name them off the top of my head.

Another option to try is to add the project to the solution, add the reference, and then create a Solution Filter (which is like a mask over the solution to exclude certain projects) if you don't want the project open while you're working.

Upvotes: 2

Related Questions