2

Let's say that I have the following projects:

Project A

Project B - References Project A

Project C - References Project B

If I set <DisableTransitiveProjectReferences>true</DisableTransitiveProjectReferences> in Project C's .csproj, Project C will not compile since Project A is not explicitly references by Project C. If I do not set this DisableTransitiveProjectReferences flag, it will compile. It seems like when I disable transitive references I'm being very "strict" on my project.

I've seen a lot of posts online about how to disable transitive references but now many on why I should or should not.

When should I explicitly disable transitive references in a C# project? What are the tradeoffs (benefits and costs) I'm implicitly taking on in my project when I choose to keep transitive references?

Tea
  • 160
  • 7
  • This is generally used to hide away a lower layer of your solution so the developer doesn't accidentally start using things they shouldn't. However, it's an opinion based question so not really a good fit for Stack Overflow I'm afraid. – DavidG Aug 16 '21 at 15:31
  • @DavidG Okay, I thought there might be a more concrete black-and-white answer here. How does disabling transitive references lead to "hiding" though? – Tea Aug 16 '21 at 15:32
  • Let's say Project A contains all you database logic and entities, you can prevent accidental use of the entities in Project C which might be your web layer for example, it is good practice to keep those things absolutely separate. – DavidG Aug 16 '21 at 15:36
  • FWIW I don't think this is a bad question (wasn't me that downvoted), in fact I think it's a good one to ask, just not on here. – DavidG Aug 16 '21 at 15:56
  • Hmmm... I think it is a good question. I agree that it's _opinion-ish_, but, saying what that does and enumerating the pros and cons is, I think, appropriate for this site. There are a lot more opinion-like questions with high vote counts here – Flydog57 Aug 16 '21 at 16:28
  • @DavidG ProjectA's public database-related classes will still be available for use in ProjectC though (through ProjectB). That's where my confusion lies, I do not see what is being hidden. by not referencing ProjectA in ProjectC. – Tea Aug 16 '21 at 17:44
  • Yes, and project B should be able to use those classes, usually as an interface between the database and the presentation layer for example. But Project C should never see A. – DavidG Aug 16 '21 at 17:53
  • @DavidG When you say "Never see", I'm assuming you mean classes in Project A should never be explicitly used in Project C. They may be implicitly used through Project B, though. Is this a correct interpretation of what you're talking about? – Tea Aug 16 '21 at 18:34
  • Yes, that's what I mean – DavidG Aug 16 '21 at 18:55

0 Answers0