Geeks With Blogs

News My Blog has been moved to https://mfreidge.wordpress.com

Michael Freidgeim's Blog My Blog has been moved to https://mfreidge.wordpress.com
To optimize performance of visual studio build I've found multiple recommendations to change CopyLocal property for dependent dlls to false,

  1. e.g. From http://stackoverflow.com/questions/690033/best-practices-for-large-solutions-in-visual-studio-2008 
  • CopyLocal? For sure turn this off

  • Always set the Copy Local property to false and enforce this via a custom msbuild step
  • My advice is to always set ‘Copy Local’ to false

Some time ago we've tried to change the setting to false, and found that it causes problem for deployment of top-level projects.

Recently I've followed the suggestion and changed the settings for middle-level projects. It didn't cause immediate issues, but I was warned by Readify Consultant Colin Savage about possible errors during deployments

I haven't undone the changes immediately and we found a few issues during testing.

There are many scenarios, when you need to have Copy Local' left to True.

The concerns are highlighted in some StackOverflow answers, but they have small number of votes.The concerns are highlighted in some StackOverflow answers, but they have small number of votes.

Top-level projects:  set copy local = true.


First of all, it doesn't work correctly for top-level projects, i.e. executables or web sites.
  • for all the references in the one at the top set copy local = true.
 
 
If you set ‘ Copy Local = false’, VS will, unless you tell it otherwise, place each assembly alone in its own .\bin\Debugdirectory. Because of this, you will need to configure VS to place assemblies together in the same directory. To do so, for each VS project, go to VS > Project Properties > Build tab > Output path, and set the Ouput path to ..\bin\Debugfor debug configuration, and ..\bin\Release for release configuration.

Second-level  dependencies:  set copy local = true.

Another example when copylocal =false fails on run-time, is when top level assembly doesn't directly referenced one of indirect dependencies.
E..g. Top-level assembly A has reference to assembly B with copylocal =true, but assembly B has reference to assembly C with copylocal =false. Most likely assembly C will be missing on runtime and will cause errors 

Copy local is important for deployment scenarios and tools. As a general rule you should use CopyLocal=True
 
and http://stackoverflow.com/questions/602765/when-should-copy-local-be-set-to-true-and-when-should-it-not?lq=1

Unfortunately there are some quirks and CopyLocal won't necessary work as expected for assembly references in secondary assemblies structured as shown below.

  • MainApp.exe
    • MyLibrary.dll
      • ThirdPartyLibrary.dll (if in the GAC CopyLocal won't copy to MainApp bin folder)

This makes xcopy deployments difficult . 

Reflection called DLLs  dependencies:  set copy local = true.
E.g user can see error "ISystem.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information."

The fix for the issue is recommended in http://stackoverflow.com/a/6200173/52277


"I solved this issue by setting the Copy Local attribute of my project's references to true."


In general, the problems with investigation of deployment issues may overweight the benefits of reduced build time.
 
Setting the Copy Local to false without considering deployment issues is not a good idea. 


 
Posted on Sunday, December 9, 2012 1:15 PM .Net Framework , Visual Studio/TFS/git | Back to top


Comments on this post: Do NOT Change "Copy Local” project references to false, unless understand subsequences.

# re: Do NOT Change "Copy Local” project references to false, unless understand subsequences.
Requesting Gravatar...
You guys are complicating the entire issue.

CopyLocal should be set to true for websites and application exes. CopyLocal should be set to false for all you DLL projects if you are dumping them into a common bin. If you don't, then you will end up overwriting newly compiled DLL's with older DLL's from your Hint Path references.
Left by George S on Jan 05, 2013 8:09 AM

# re: Do NOT Change "Copy Local” project references to false, unless understand subsequences.
Requesting Gravatar...
@George

I think the issue mentioned in 'Second-level dependencies' will still exist if the host is a webproject.
Left by Sven Neubert on Feb 05, 2013 4:01 AM

# re: Do NOT Change "Copy Local” project references to false, unless understand subsequences.
Requesting Gravatar...
This blog entry is completely unreadable. It's not 1989 anymore...
Left by foo on Jun 26, 2013 7:14 PM

# Regarding Kendo UI in Azure
Requesting Gravatar...
I have a project with Kendo UI, In Azure no kendo controls are working, can you guide me regarding DLL that has to be added in this case. And we are trying to host in the Azure Cloud Server.

It works fine in Non-Azure.


For Kendo Grid: Error is ::Index must be within the bounds of the List.Parameter name: index

For Kendo AutoComplete ::Entry point was not found.
Left by Pradeep Kumar T on Oct 07, 2013 4:40 PM

# re: Do NOT Change "Copy Local” project references to false, unless understand subsequences.
Requesting Gravatar...

Nice article. Right, changing copy to local as true or false really depends. Fortunately, the Visual Smarter has a lot of widgets which can set reference properties automatically and can also help copy, add, remove, and update references automatically. The Multi-Reference Tweaker utility is also nice to try.

http://visualsmarter.blogspot.com/2015/11/project-widgets-of-visual-smarter.html
http://visualsmarter.blogspot.com/2015/04/visual-studio-reference-concerns-and.html
Left by visual smarter on Nov 28, 2015 6:20 PM

# re: Do NOT Change "Copy Local” project references to false, unless understand subsequences.
Requesting Gravatar...
Nice. But do you propose a solution for this ? I mean for solution that containes more than 200 projectes, copying hundreds of references in local on each build is painfull.
Left by No on Mar 29, 2016 11:28 PM

Your comment:
 (will show your gravatar)


Copyright © Michael Freidgeim | Powered by: GeeksWithBlogs.net | Join free