Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reference DLLs in ASP.NET without \Bin or GAC

I have an ASP.NET project under source control (Subversion). For various reasons, I don't want to add the \Bin directory or its contents to source control, so I have it svn:ignored. DLLs are loaded into here during a Visual Studio build, and I can start with a clean directory and/or delete all the contents of this directory and still have a successful build.

There are two ways that I reference code for inclusion in the project:

  1. In the Web.config element //configuration/configSections/system.web/compilation/assemblies. I can <add> any DLL that's in the GAC this way. I do this for all of the System dlls.
  2. In the VS Solution, there's a setting at Project/ProjectSection/ProjectReferences that lets me specify included references to other projects in the solution.

(Note that this is different than non-web projects, where all references to external dependencies are stored in the project file. There's no project file for VS web projects so they have to be stored somewhere else.)

Now I have a 3rd-party compiled DLL that I'd like to include in the project. Unfortunately, none of the referencing options I've found seem to work for me:

  1. Referencing via web.config/system.web/compilation/assemblies doesn't work unless the DLL exists in the GAC; you can't use a file path. I'd really like to avoid a GAC dependency as it will mean an extra step to make the project work on every target machine.
  2. I haven't found a way to include a file reference in the solution like I can do with project references.
  3. Any time I add a file reference using VS's "Add Reference" dialog, it merely copies the DLL to the \Bin directory. That won't work for me as my \Bin directory isn't persistent across systems.

Is there another way I can make a reference to a DLL file and have it stick?

like image 344
Craig Walker Avatar asked Jan 13 '10 18:01

Craig Walker


2 Answers

If you are doing any kind of serious development I would recommend migrating away from the web site project and to a web project as this allows you to manage these kind of dependencies in the same manner across your entire solution.

However, assuming you cannot do that, place all of the assemblies that you need to reference from the web project into a folder somewhere ( e.g. lib\web ) and add a pre-build event to your web project that copies the content of that folder into the bin folder of the web directory. Now whenever you want to add a dependency to your web project you can drop it in the lib\web folder, and add the reference. Whenever you build, all of the referenced assemblies will be copied into the folder so you can delete the bin folder or do a clean checkout and not have any issue.

like image 70
Neal Avatar answered Oct 12 '22 01:10

Neal


Technically, in step 3 a little more happens. Visual Studio copies the DLL to your \Bin directory and adds a name.dll.refresh file that contains the path to the original DLL. With SourceSafe, the .refresh file is under version control, so that when you setup a new system and get the latest code from SourceSafe, Visual Studio can find and copy the DLL from the specified location. You should be able to put the .refresh file in svn and have everything work.

Also, I generally create a \Common directory above my project directory, which is where I put the DLLs, and I include that directory in the solution (and source control), so that each version of my project in source control has the correct DLLs.

like image 28
Jason Berkan Avatar answered Oct 12 '22 02:10

Jason Berkan