8

Any ideas how to force a GAC DLL into referenced?

Here is my issue, I constantly use a 3rd party DLL that registers itself into the GAC, and when I use it in my project, it reads it from the gac, and when I deploy, I'm always forgetting to add the DLLs since it is not located in the Bin/Referenced folder.

Anyway to force Visual Studio to add the DLL instead of from GAC?

Jon Seigel
  • 12,251
  • 8
  • 58
  • 92
jaekie
  • 2,283
  • 4
  • 30
  • 52

4 Answers4

12

Copy Local only works if the GAC'd assembly if one reference level deep. For instance, if you have a project that references the GAC'd assembly, and that project if referenced by your web project, then while yes, the GAC'd assembly will be copied to the first project's bin folder, but it won't be copied to your web project's bin folder.

The solution, then, is to directly set a reference in the web project to the GAC'd assembly, and specify Copy Local. Even though the web project doesn't directly use the reference in this case, it will copy it to the web application's bin folder.

Jason C
  • 121
  • 1
  • 2
  • 2
    The solution is fraught with danger particularly when code cleanup tools become involved. If something like Resharper tells you a reference is "not required" (think large project team) and these references are cleaned up, you are back to square one. – Shiv Apr 14 '14 at 04:59
7

Right click on the assembly reference, select properties, and change "Copy Local" to true. That will cause it to copy the assembly into the deployment directory

Joel Martinez
  • 46,929
  • 26
  • 130
  • 185
  • 9
    Warning: This isn't transitive! So if `MyExe` references `MyLib` references `DllInGac` then `MyLib` will be copied locally, but *its* dependencies will not be copied to `MyExe` if they're already in the GAC. – Eamon Nerbonne Jun 19 '12 at 10:42
5

Select the dll in your references and set CopyLocal=true in the properties window.

Fergal Moran
  • 4,525
  • 5
  • 39
  • 54
2

Select the reference and set the Copy Local property to True

Daniel Renshaw
  • 33,729
  • 8
  • 75
  • 94