?
Solved

How to reference a dll without VStudio making a copy of it -- the original location is referenced

Posted on 2009-07-08
12
Medium Priority
?
251 Views
Last Modified: 2013-12-17
The scenario is like this: let's say you have a bunch of utility methods and classes all contained in one dynamic library (dll).  You use / reference that dll in many projects, but you also are frequently making changes to this dll (improvements, etc).  But with every change, you have to find each project using this dll and update them with the new one.  Not fun, not practical.  I would like to do this: when you go to "References" and "Add Reference", when you browse and add the dll, that VStudio just makes reference to the original folder location, not making a local copy into your xy or z project that's using it.  I'm wanting to avoid installing to the GAC, (for the reason just stated: "but you also are frequently making changes to this dll (improvements, etc)"; this is too fluctuating to add there just yet) ... but ... maybe that is the only way to do this?  By the way  --  I'm only talking about being in Debug mode, which also means, of course, staying on the same computer / harddrive, so the referenced dll location of course must remain valid (with the dll there where specified) -- in actual deployment, of course the dlls would have to ship along in the deployed project.  

Thanks
0
Comment
Question by:Sperling1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
  • 3
12 Comments
 
LVL 41

Expert Comment

by:graye
ID: 24807810
That's not really a practical idea...   besides, that problem is precisely why the GAC was created.
For example, the .Net Framework was designed to operate in 1 of 2 ways... either using "shared assemblies" - DLLs in the Global Assembly Cache (GAC) or by "private assemblies"-DLLs in the applications own directory (the side-by-side approach).  The side-by-side technique *requires* the the DLLs be in the same directory (or a directly below) the application's running directory.   The only way to override this is to write code to manually load DLLs (which seems a bit overkill to me)
Since a method already exists to share DLLs, I'd recommend that you use it.
Is there is specific reason for "going rogue"?
0
 
LVL 16

Expert Comment

by:ToddBeaulieu
ID: 24807823
Have you tried unchecking the "copy local" option for references to this dll?

I don't see why you couldn't GAC it, really. Just throw a post-build event on the dll project and you'll never have to think about it again.
0
 
LVL 3

Author Comment

by:Sperling1
ID: 24809476
Graye, those are good points.  Those points may be right - but I had to ask.  No, I definitely am not looking for some 'overkill' route -- in that case I would go with GAC.  But this answers Todd's question too: one reason is that I've never entered anything in the Gac yet, other is I'm expecting this to change a lot on me.  

Todd: Where would I "uncheck" "copy local"??  Please tell me all the steps where I can see that.  Is it in Tools / Options?

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 16

Accepted Solution

by:
ToddBeaulieu earned 2000 total points
ID: 24809539
If you select an existing reference and go to its properties, there is a true/false (sorry, not a check) for "Copy Local". I've rarely used it, but I think it might do the trick for you. If you start to run into issues, you should really consider the GAC. It's painless, we promise!
0
 
LVL 3

Author Comment

by:Sperling1
ID: 24810067
Wunderbar!  
Well done Todd, that exactly does the job.  I thought there was a simple, top level way of doing this.  I still should get used to the GAC, but I bet there are many times where this will be preferrable while in development.  Just a side note: C#3.0 in a Nutshell / Albaharis p 544-5 list some reasons why GAC is not ALWAYS preferrable.

Thanks again Todd!
0
 
LVL 41

Expert Comment

by:graye
ID: 24810425
BTW:  You're gonna have trouble when you switch to deploying the DLLs on a production machine.
0
 
LVL 3

Author Comment

by:Sperling1
ID: 24810479
graye:
Good point to keep in mind, thanks.
0
 
LVL 16

Expert Comment

by:ToddBeaulieu
ID: 24812044
What touble are you referring to? As long as the library isn't being revisioned out of binding (major.minor), what is the issue?

btw - I wouldn't use this technique in any kind of team environment. You'd find missing DLLs all over the place. Team Build wouldn't pull down the DLL, either and would fail.

I'd probably put the dll in a common BIN folder, have the post-build stick a copy there (if you want auto-deployment to your other applications) and then build my references (with Copy Local) to THAT folder. That solves a ton of issues.
0
 
LVL 41

Expert Comment

by:graye
ID: 24812643
The .Net framework follows a strict set of rules on how an assembly find its referenced DLLs at runtime.   The rule are:
  1. Use exsiting bound assembly if any
  2. Use the GAC
  3. Probe for the file starting at the applications "root" directory
Obviously these rules don't apply to COM-based references
http://msdn.microsoft.com/en-us/library/yx7xezcf.aspx
http://msdn.microsoft.com/en-us/library/15hyw9x3.aspx
This is why Visual Studio defaults to "Copy Local"... because the probing rules do not allow you to specific a directory outside the application's root.
0
 
LVL 16

Expert Comment

by:ToddBeaulieu
ID: 24812653
Hmmm. I'm still not sure what the proposed problem is at deployment.

BTW - you can specifiy a specific location for an assembly using CodeBase.
0
 
LVL 41

Expert Comment

by:graye
ID: 24813032
Hummm... I thought <codeBase> was just for web applications... I'll have to check that out.
The <codeBase> feature will only allow you to specify a path outside the applications root, *if* you're using an assembly that is strongly-named...   Which follows the same rules as putting the assembly in the GAC.   And, if you're gonna do that, then why not just use the GAC and be done with it.
This *is* however, an alternate solution...   you could put all of the applications (and their reference private assemblies) into the same directory.   I could see how this would work fairly well over a network share
0
 
LVL 16

Expert Comment

by:ToddBeaulieu
ID: 24813120
You know, I sign everything (Team Build), but I don't use the GAC. For a Team Project that makes use of common libraries, I put the compiled binaries into an EXT folder of that project. This allows me to push new versions of the common libraries only to those projects that are ready for it, acommodating breaking changes, as well as eliminating the need for regression testing of applications we don't want to touch.

As for CodeBase, I used that with interop assembly wrappers in the past. It's nothing more than a first-chance binding hint for Fusion.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

741 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question