luke77
luke77

Reputation: 232

C# Project dependencies without reference

I have a solution with a multiple projects.

Let's say I have projects :

P2 is my startup project.

I would like to configure P2 with a dependency to P4 so P4 will be build and P4 and the dependencies pushed to the bin folder of P2 but I don't want P2's dll to have a .net reference to P4

I partially managed to do that with a specific project reference in the csproj :

<ProjectReference Include="..\P4\P4.csproj">
  <ReferenceOutputAssembly>false</ReferenceOutputAssembly>
  <OutputItemType>Content</OutputItemType>
  <CopyToOutputDirectory>Always</CopyToOutputDirectory>
  <Targets>Build;DebugSymbolsProjectOutputGroup</Targets>
</ProjectReference>

But this solution does only add P4 and not the dependencies (P3 and N1)

Does anyone knows how to do that ?

Thanks

Upvotes: 5

Views: 3374

Answers (1)

Leo Liu
Leo Liu

Reputation: 76700

Does anyone knows how to do that?

This is default behavior for indirect dependencies.

If project P4 doesn't actually contain any code that explicitly uses reference project P3 and nuget package N1, VS/MSBuild doesn't detect that P3, N1 is required by P2, so MSBuild does not think its necessary to copy the P3, N1 to the output folder of P2. That is the reason why only add P4 and not the dependencies (P3 and N1) into P2's bin directory.

To resolve this issue, you can directly reference P3, N1 to project P2 or add a copy command line in the P2`s build event to copy those dll to the bin folder.

Besides, you can also add dummy code to a file in project P2 that uses project reference P3, N1.

See MSBuild doesn't copy references (DLL files) if using project dependencies in solution for some more details.

Hope this helps.

Upvotes: 1

Related Questions