5

Background

My assembly (a DLL) is being loaded by a third party application, I have no control over how it is loaded. The third party app will load all assemblies in a given directory.

Problem

If my assembly and another assembly use the same library, but different versions, they will both be in the same directory and will conflict. I have already researched the <probing> config file directive, and Assembly Resolvers, so I know how to create a subdirectory and have my assembly search it for references.

Need

I need some way of configuring visual studio to build my main DLL into the root folder, and all references into a subfolder. Preferably during build (since I configured my build to go directly to the correct folder.

Ped7g
  • 15,245
  • 2
  • 24
  • 50
David Colwell
  • 2,342
  • 16
  • 30
  • Unfortunately this could be a bigger problem than just where the DLLs are located. Even if the DLLs are loaded from their own respective directories, if they are loaded into the same application domain there may be conflicts. If you know for sure this isn't an issue, you could use something like Fody Costura to simply wrap your dependencies up and ship as a single DLL. – Paul Nov 01 '16 at 23:57
  • Also I should mention, if you don't want to wrap them into a single DLL, you could use a post-build event to simply copy all DLLs except for your own assembly into a sub-directory. The problem is then whether or not the third party DLL knows how to load those dependencies from the sub-directory. – Paul Nov 01 '16 at 23:59
  • Thanks @Paul, the third party tool loading my assemblies is not too big a problem, Assembly Resolvers are currently handling that part fine. Currently I'm looking at a post build task, or Raidensan's solution being the best – David Colwell Nov 02 '16 at 06:36

1 Answers1

3

You can put your references in separate folders. Here is how:

  • Add a folder to your project root.

enter image description here

  • Rename folder to appropriate name.

enter image description here

  • Right-Click on folder and from Add -> Existing Item

enter image description here

  • Now select & add any reference assembly to this folder. You can add files as a link

  • Right-Click References and go to Add Reference -> Browse

  • Navigate to your newly created folder and select assemblies.

  • Set Copy to Local to True for each Reference.

  • Build your project.

raidensan
  • 969
  • 10
  • 26
  • 1
    Thanks @raidensan, its a good idea, the truth is that most of my references are added from NuGet as package dependencies, so its a bit of a pain to go find them all manually. If there is no other solution, this is probably what I will go with – David Colwell Nov 02 '16 at 06:34
  • 1
    Check this [answer](http://stackoverflow.com/a/4197201/2928544) for nuget packages. It is possible to achieve what you need. – raidensan Nov 02 '16 at 06:37
  • 1
    Your link to the answer about using nuget.config only specifies where the packages needed for the solution should be restored to. But when building the solution, all the dependencies get written to the `bin` folder as well, and not in a subfolder. – Zev Spitz May 25 '20 at 10:53