Is it possible to put in place automatically enforced restrictions on the dependencies allowed between projects in Visual Studio?
For example, say I have three simple layers; UI, Business and Data. Can I enforce that UI should never hold a reference to Data and stop the solution from building if such a thing were to happen?
I'd expect a persistent developer to be able to get around this but can see the benefits of it in terms of guiding developers and detecting mistakes early on.
You can't directly or forcibly prevent references, but what you can do is set up the references yourself, this will help with your scenario because people will not be able to add references back (hard circular references). This doesn't stop people using libraries like MEF or Unity from jumping around in a very loose decoupled way - it is entirely possible that they resolve or load assemblies that you don't expect and call in to them (I call this a logical circular dependency). The only way to guard against this is vigilance via code reviews.
Once you have your references correctly set up you can then monitor the changes to the project files to tell when other hard references have been added. Any source control system makes version compare trivially easy, and some (i.e. TFS) will even allow you to be notified when specific files are changed (like when a project file is changed).
Once again, the surest option you have is code reviews.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With