Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deploying assemblies to the bin folder without adding references to the project

Tags:

.net

build

I am heavily using dependency injection in my application. As such, my components reference interfaces, and the concrete implementations are known only to my IoC container, configured through XML files.

A consequence of this design is that I end up needing assemblies in my bin folder (e.g. Newtonsoft.Json, SqlLite) that I have no need to reference in my project. In fact, I explictly do not want references, as I or my team may accidentally refer to a concrete implementation rather than an interface, thereby destroying the advantages of the DI we're using.

The _bin_DeployableAssemblies folder introduced in VS 2010 SP1 was useful for this scenario, but applied only to web projects (I'm personally using MVC3 and ok with that, but it doesn't solve the general problem. However, it appears to be more or less deprecated in VS11 Beta. Copying the files into the bin directory prior to build feels icky - the bin folder is no longer a container for build artifacts. I suppose a custom post-build event could be used, but it seems there should be something more "out of the box" to solve this problem. Am I stuck with post-build? What other ways are there to tackle this issue?

like image 555
Emil Lerch Avatar asked Oct 22 '25 06:10

Emil Lerch


1 Answers

There are a couple of ways to handle this:

  1. A post-build event to copy the files into the bin folder will handle this.
  2. Include the files as content items in the Project, but not as references. They can be set to copy to the output folder on build.

I sometimes use the second option. This does have the advantage of keeping the "dependency" obvious to developers, while still preventing them from actually using the types defined within the assemblies, as they are not references and the compiler will not see them as available.

like image 82
Reed Copsey Avatar answered Oct 23 '25 21:10

Reed Copsey



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!