Project References when using Unity

Dec 4, 2008 at 9:49 PM
Consider these Projects:
- Website
- BusinessLogic
- DataAccessInterfaces
- DataAccessADO
- DataAccessEntityFramework

MainSolution.sln >> includes all projects
DataAccessSolution.sln >> includes DataAccessInterfaces, DataAccessADO and DataAccessEntityFramework projects, plus Test projects for unit testing.

BusinessLogic has a reference to DataAccessInterfaces.  Unity is used to determine if a class from DataAccessADO or DataAccessEntityFramework is returned and used.

Because BusinessLogic does not have a reference to DataAccessADO or DataAccessEntityFramework, those DLLs are not copied to the website /bin automatically.  Now I initially solved this problem with a post-build event in each of the ADO and EF projects, that copied their DLLs to the /bin folder of the Website.  This worked fine.  I did not think I wanted to add references to the ADO and EF projects in the BusinessLogic project because that might expose more than just the Interfaces would.

Now, however, upon creating the DataAccessSolution for some unit tests (I know should have been done first, but I'm learning... baby steps!), when I build the solution, it fails because it wants to copy files to the website folders using incorrect post-build paths (based on the solution location).

So the question is, when using Unity, do you still create project references so VS.NET copies the DLLs automatically?  (in this case BusinessLogic to DataAccessADO and BusinessLogic to DataAccessEntityFramework)

What say you Unity gurus?  What is best practice?


Dec 5, 2008 at 10:13 PM
Upon further exploration, I thought I would try to create a project reference between BusinessLogic and DataAccessADO, even though a direct reference is not required, I thought the reference would still handle the copy of assemblies for me.  I was wrong.  I guess VS.NET is smart enough to realize that there are no code based dependencies that it can see, so it ignores the DataAccessADO assembly.

I guess I have to use Post Build events for this?
Dec 9, 2008 at 2:47 AM
Edited Dec 9, 2008 at 3:34 AM
You don't necessarily have to create a project reference, you just need to copy the assembly to the bin directory of the project.  For the test projects, you could edit your test configuration and add the same assemblies to the deployment items. 

Sarah Urmeneta
Global Technology & Solutions
Avanade, Inc.