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)
相关问题
- How to know full paths to DLL's from .csproj f
- Importing NuGet references through a local project
- Visual Studio 2019 - error MSB8020: The build tool
- 'System.Threading.ThreadAbortException' in
- VS2017 RC - The following error occurred when tryi
相关文章
- How to show location of errors, references to memb
- How to track MongoDB requests from a console appli
- Visual Studio Hangs on Loading UI Library
- How to use Mercurial from Visual Studio 2010?
- Copy different file to output directory for releas
- Edit & Continue doesn't work
- “Csc.exe” exited with code -1073741819
- Visual Studio: Is there an incremental search for
Regarding the solution posted by @herzbube, if you want to turn off "Copy Local" for all (or most) of the references in your .csproj file, you don't need to set
<Private>False</Private>
individually on eachReference
, you can just put the following directly in the .csproj:This doesn't affect projects referenced with
<ProjectReference>
, but you can do the same thing--either instead or as well--for those:If you want both of these, you can merge them into a single group:
Make sure you put these overrides prior to the first actual
<Reference ...>
or<ProjectReference ...>
you want to affect because these blocks will only apply to those references that appear below them. Then, if there are a few that you do actually want to be locally copied, you can just override those back individually (i.e., within the individual tag itself), this time usingTrue
.For more advanced cases you can switch the overriding value back and forth between True and False multiple times in the same .csproj file. Another advanced technique would be to strategically place some of your references below these blocks, and others above, so the latter won't be affected.
All of this should make the XML in your .csproj much cleaner and easier to read. But there's even more good news, so read on...
As for selecting which projects should be be marked
<Private>False</Private>
this will usually depend on the specific situation, but there is something fundamental everyone can and should do for starters. It's a step so basic, simple and effective and it delivers such huge MSBuild reliability improvements1. and build-time speedup--and with little downside--that every large solution that uses the the default (i.e. local per-project) C# output locations should almost always make this adjustment:This works perfectly because the .csproj for a class library may reference multiple other class libraries, but the .csproj for an executable usually never references another executable. Thus, for every locally-built library, the only .dll in its
bin
folder will be itself, whereas every locally-built application will contain the full set of locally-built libraries it references.Conveniently, nothing changes for the referenced libraries that are not built by your solution, since these usually use
<Reference>
instead of<ProjectReference>
, and we didn't modify the former tag at all. But do note the assumption just mentioned; if it is violated by some of your projects, you may need to make some adjustments.[1.] Reliability improvements could be related to file collisions that may occur when gathering the same library from multiple disjoint paths in a dependency graph, especially in concurrent builds.
Starting with msbuild v 15 you can copy a single file called Directory.Build.props in the root folder that contains your source:
Nothing more to do! This works well with Visual Studio 2017 and also the vNext Build. May you 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
Bumping this because it seems there's now a nuget package allowing exactly this...
https://nuget.org/packages/CopyLocalFalse
Haven't tried yet, just hoping it helps.
Actually, you can. You need a couple things:
.targets
file that makes copylocal (<Private>
tag, to be precise) false by default..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 modifyClass.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:
There must be better solution for that, but haven't found it yet.
We don't use a .targets files (as suggested in the answer by ya23), so we just edit the
.csproj
project file manually in a text editor and add the<Private>
element to the reference, like this:The value of the
<Private>
element matches the value of the "Copy local" property. For instance, if<Private>
is set to False, then "Copy local" is also false..No - Visual Studio uses an internal set of rules to determine what to set Copy Local to.
From MSDN: