copy-to-output-directory
Installation
SKILL.md
Choosing a CopyToOutputDirectory Mode
Overview
The CopyToOutputDirectory metadata (and its publish counterpart CopyToPublishDirectory) controls whether an item — Content, None, EmbeddedResource, or Compile — is copied next to your build output, and under what conditions the copy happens. Picking the wrong mode causes either stale files in bin/ or an unnecessary per-build performance hit.
As of MSBuild 17.13 / .NET SDK 9.0.2xx there are four values:
| Mode | Copies when… | Incremental cost | Typical use |
|---|---|---|---|
Never (default) |
Never | None | Files not needed at runtime |
PreserveNewest |
Source is newer than destination (or destination missing) | Cheap (timestamp check) | The common case — source files you edit |
Always |
Every build, unconditionally | Expensive — copies on every build even in no-op builds | Legacy workaround; avoid (see below) |
IfDifferent |
Source differs from destination in either direction (newer or older, or size differs, or destination missing) | Cheap (timestamp + size check) | Destination may be mutated between builds |