
copy-to-output-directory
Choosing an MSBuild CopyToOutputDirectory / CopyToPublishDirectory mode: Never
by dotnetFree
Description
Copy to Output Directory is an MSBuild agent skill from the dotnet/skills repository that helps the agent choose the right CopyToOutputDirectory or CopyToPublishDirectory value for project items such as Content, None, EmbeddedResource or Compile. The wrong choice leads either to stale files in bin or to a needless copy on every build. The skill compares the four modes available as of MSBuild 17.13 and .NET SDK 9.0.2xx: Never, the default, for files not needed at runtime; PreserveNewest, a cheap timestamp check suited to most edited source files; Always, which copies on every build and is treated as a legacy workaround to avoid; and IfDifferent, which checks timestamp and size in both directions for destinations that may change between builds.…
Highlights
- Explains Never, PreserveNewest, Always and IfDifferent
- Covers build output and publish directories
- Notes the incremental build cost of each mode
- IfDifferent guidance for MSBuild 17.13 and later
Ratings & Reviews
No ratings yet
Be the first to rate copy-to-output-directory.
People also visit
copy-to-output-directory FAQ
Which mode should I use most of the time?
The skill describes PreserveNewest as the common case for source files you edit, because it only copies when the source is newer and costs a cheap timestamp check.
Why avoid Always?
It copies on every build, even builds where nothing changed, which slows builds. The skill calls it a legacy workaround.
When is IfDifferent useful?
When the destination file may be changed between builds. It copies if the source differs in either direction or by size. It needs MSBuild 17.13 / .NET SDK 9.0.2xx or later.
How do I add this skill to my agent?
Use the skills CLI: `npx skills add https://github.com/dotnet/skills --skill copy-to-output-directory`. This pulls the skill from dotnet/skills on GitHub.
Has the skill been security audited?
Yes. Results shown on skills.sh: Gen Agent Trust Hub: Pass, Socket: Pass, Snyk: Pass.
What are the best copy-to-output-directory alternatives?
Popular alternatives to copy-to-output-directory include including-generated-files, directory-build-organization and check-bin-obj-clash. See all copy-to-output-directory alternatives


