Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set "Copy Local" to False by default?

Can I set the default-option of "Copy Local" in Visual Studio to False? In most times, when I add a dll as dependency of a project, I want the Copy Local property set to False. Per default, it is True. Is there a way to change the default behaviour of Visual Studio? (2008)

like image 416
dr pain Avatar asked Jun 23 '10 11:06

dr pain


People also ask

What does Copy local mean in Visual Studio?

Copy Local essentially means I must manually deploy this DLL in order for my application to work. When it's false it essentially means "I depend on another component which must be installed separately or chained, the DLL will just be there already".


2 Answers

No - Visual Studio uses an internal set of rules to determine what to set Copy Local to.

From MSDN:

  1. If the reference is another project, called a project-to-project reference, then the value is true.
  2. If the assembly is found in the global assembly cache, the value is false.
  3. As a special case, the value for the mscorlib.dll reference is false.
  4. If the assembly is found in the Framework SDK folder, then the value is false.
  5. Otherwise, the value is true.
like image 66
Leom Burke Avatar answered Nov 09 '22 16:11

Leom Burke


Actually, you can. You need a couple things:

  1. Create .targets file that makes copylocal (<Private> tag, to be precise) false by default.
  2. Import the target in .csproj files. You can add it in the very last line, before closing </Project> tag, it'll look like <Import Project="..\Build\yourtarget.targets" />.

Now each project with this target has copylocal disabled by default.

The drawback is that you need to modify each and every csproj file, including new ones. You can work around the new project issue by modifying the VS project template. Instead of Class.cs described in the blog article, you need to modify Class.vstemplate (in the same zip file).

With that approach, there's one more problem - the path itself. If you use hardcoded relative path in newly-generated csproj files, they may be wrong (unless you have flat project structure).

You can:

  • Make VS generate correct relative path. Not sure how to do that and if that's even possible.
  • Ignore it and change the path manually for each new csproj (depending on the number of new project you have, while not ideal, that may be tolerable).
  • Use the environment variable instead of relative path. In that case every developer will need the same variable set.

There must be better solution for that, but haven't found it yet.

like image 30
ya23 Avatar answered Nov 09 '22 17:11

ya23