5

I have a solution with a multiple projects.

Let's say I have projects :

  • P1
  • P2 with a reference to P1
  • P3
  • P4 with a reference to P1 and P3 a dependency to a nugget package N1

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

luke77
  • 221
  • 3
  • 15

1 Answers1

1

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.

Leo Liu
  • 71,098
  • 10
  • 114
  • 135
  • Hi thanks for your answer. **P4** use directly **P3** and **N1**. But effectively, **P2** does not use **P4** or **P3** or **N1** – luke77 Feb 09 '18 at 09:40
  • @luke77, what do you mean "`I would like to configure P2 with a dependency to P4`"? Do you want P2 reference P4 or P4 reference P2? Need confirm. – Leo Liu Feb 09 '18 at 09:47
  • Sorry, by dependency I mean a build dependency. If I build P2, I want also P4 to be built and P4, P3, N1 "paste" to P2's bin. – luke77 Feb 09 '18 at 16:03
  • 1
    @luke77, if you want `If I build P2, I want also P4 to be built`, why do not you set P2 reference P4? You do not want set that? If yes, you can add a custom task in the P2 to build P4 before build P2 and copy P3, N1 to P2`s bin folder. – Leo Liu Feb 12 '18 at 02:15
  • @luke77, what about this issue now? Have you resolve it? If not, Would you please let me know the latest information about this issue? – Leo Liu Feb 13 '18 at 06:09
  • hi, sorry for my late answer. I could not find a way to do it as I would like. I thinking about making a real reference on P4 from P2 to automatically include what is required but with conditionnal parameters passed during the build to include or not P4 (depending on the target I'm building for) – luke77 Feb 14 '18 at 13:45
  • @luke77, Thanks for your response, it would be hard to achieve the function as you like, but like our previous discussion, using certain workaround instead of the it would be a path for this question. Have a nice day:) – Leo Liu Feb 15 '18 at 07:31
  • 1
    @LeoLiu-MSFT: You mentioned adding a custom task to build P4 and copy P3, N1 to P2`s bin folder. Would you please be so kind to point me to an example/snippet/discussion on the topic? – Vlad Dec 04 '19 at 12:07