3

I have a C# solution that I am using dependency injection to resolve references between dlls. I have an exe project and some other dll projects that are not referenced by the exe (It uses the dlls through the IoC container). The project settings are the default, visual studio settings where it builds each dll in it's own folder. Since the exe doesn't reference the dlls, they never get copied to the output directory of the exe and don't get found by the IoC framework.

How do you handle this? Do you build them all in the same directory? Use post build copy commands? Or something else?

NotDan
  • 31,709
  • 36
  • 116
  • 156

3 Answers3

5

I typically handle this by using a post-build copy command (using Build Events, so they're automatic) that puts the dependency assemblies into a shared folder.

I then make sure this folder is included in my IoC container's search path, so they get found.

Another, similar option, is to use a build event on your main application project. It can then copy the dependencies into an appropriate folder. This has the advantage of allowing different dependencies to be used for different applications within the same solution, while still being easy to maintain.

Reed Copsey
  • 554,122
  • 78
  • 1,158
  • 1,373
  • We actually have a build event now in the main project.. but the problem is if it doesn't change, and you press F5, the projects that did change get built but the copy doesn't happen b/c the exe didn't change/build. – NotDan Jan 05 '11 at 18:23
  • @NotDan: Yeah - that's the problem with the second (pull) approach. There are options - however, mainly - Right click on the solution in Solution Explorer, and choose "Project Dependencies" - make sure to add the libraries as dependencies of the main project. It should force them to rebuild... – Reed Copsey Jan 05 '11 at 19:29
  • @ReedCopsey There is no "main" project if you have multiple composition roots (e.g. wcf service, mvc/web app). Adding 20 references to each is not very pleasant. Did you find a better solution? Also, how do you handle paths of shared libs on the production? – Andriy Drozdyuk Jul 15 '13 at 13:31
  • @drozzy Adding the references isn't too bad, since it's a one time operation - yes, its tedious, but it's really not that big of a deal. As for shared libs, it really just depends - there are a ton of options, mostly based on which IoC container you're using. – Reed Copsey Jul 15 '13 at 16:07
  • @ReedCopsey Indeed, I think I will go with adding hard references to one "shared" project which (using mef) creates a registration builder and returns that. I wish there was a more elegant solution... – Andriy Drozdyuk Jul 15 '13 at 16:33
2

Use post build copy commands or change output directory for all projects to common directory

Arsen Mkrtchyan
  • 49,896
  • 32
  • 148
  • 184
0

I would (and did) use post build copy commands. Create a .BAT file that makes all the necessary copies, attach it to the post-build event and you're done.

rsenna
  • 11,775
  • 1
  • 54
  • 60