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

2
  • and why cannot you put all references into P2? Commented Feb 8, 2018 at 13:45
  • I don't want to. Depending on how and where P2 will be deployed, not all the P4-like projects will be deployed. Commented Feb 8, 2018 at 17:16

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

8 Comments

Hi thanks for your answer. P4 use directly P3 and N1. But effectively, P2 does not use P4 or P3 or N1
@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.
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, 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.
@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?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.