Set "Copy Local" to False by default?

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.


Starting with msbuild v 15 you can copy a single file called Directory.Build.props in the root folder that contains your source:

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemDefinitionGroup>
  <Reference>
    <Private>False</Private>
  </Reference>
  <ProjectReference>
     <Private>False</Private>
  </ProjectReference>
</ItemDefinitionGroup>
</Project>

Nothing more to do! This works well with Visual Studio 2017 and also the vNext Build. You might have to close Visual Studio and than open your solution again to take the file effect.

https://docs.microsoft.com/en-us/visualstudio/msbuild/customize-your-build#directorybuildprops-and-directorybuildtargets


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.