copy-to-output-directory
यह क्या करती है
यह स्किल MSBuild में project फ़ाइलों को build output में कॉपी करने का तरीका चुनने का मार्गदर्शन देती है। यह उन डेवलपर के लिए है जिनके builds इसलिए धीमे हैं क्योंकि हर build पर फ़ाइलें कॉपी होती हैं, या जिनके output फ़ोल्डर में पुरानी फ़ाइलें रहती हैं।
कब इस्तेमाल करें
- ✓जब build इसलिए धीमा हो क्योंकि हर build पर फ़ाइलें कॉपी होती हैं।
- ✓जब output फ़ाइलें पुरानी हों या किसी बदलाव के बाद अपडेट न हों।
- ✓जब आपको content या data फ़ाइलों के लिए copy मोड में से चुनना हो।
Skill का लिंक
https://github.com/dotnet/skills/blob/main/plugins/dotnet-msbuild/skills/copy-to-output-directory/SKILL.mdइसे कॉपी करके अपने AI (Claude, ChatGPT या Cursor) में पेस्ट करें और निर्देशों का पालन करने को कहें।
कैसे इस्तेमाल करें
सबसे आसान तरीका: मैसेज कॉपी करके अपने AI में पेस्ट करें। वह skill पढ़कर निर्देशों का पालन करेगा।
पेस्ट करने के लिए तैयार मैसेज
Claude Code, Codex या Cursor के लिए: प्रोजेक्ट फ़ोल्डर में चलाएँ और skill इंस्टॉल हो जाएगी।
SKILL.md डाउनलोड करें और अपने एजेंट के skills फ़ोल्डर में रखें।
AI से क्या माँगें: उदाहरण
“मेरा build बड़ी टेस्ट डेटा फ़ाइल हर बार कॉपी करता है, भले ही कुछ न बदला हो। सही copy सेटिंग चुनिए।”
हर हफ़्ते 5 नई skills, 1 मिनट में पढ़ें।
यह कैसे काम करती है
एजेंट देखता है कि runtime पर हर फ़ाइल कैसे इस्तेमाल होती है, फिर सही copy मोड सुझाता है, जैसे सबसे नई फ़ाइल रखना या सिर्फ़ अलग होने पर कॉपी करना।
तकनीकी सामग्री (मूल SKILL.md)
लेखक का मूल टेक्स्ट, अंग्रेज़ी में, सीधे GitHub से।
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 |
<ItemGroup>
<None Include="appsettings.json" CopyToOutputDirectory="PreserveNewest" />
<None Include="testdata\seed.db" CopyToOutputDirectory="IfDifferent" />
</ItemGroup>
You can use either the attribute form shown above or the child-element form:
<None Include="testdata\seed.db">
<CopyToOutputDirectory>IfDifferent</CopyToOutputDirectory>
</None>
Why Always is usually the wrong choice
Always re-copies the file on every build, including otherwise-clean incremental/no-op builds. On projects with many or large content files this is a measurable, recurring cost and a common cause of "why is my no-op build not instant?" reports.
Historically Always was the only way to handle a specific scenario: the destination file can change between builds — for example an SQLite database, a storage/state file, or a config file that a test run mutates. With PreserveNewest, if the destination is modified (making its timestamp newer than the source) MSBuild will not restore the original source file, because the source is no longer newer. People reached for Always to force the file back into a known-good state — paying the copy cost on every build as a side effect.
IfDifferent: copy when different, in either direction
IfDifferent is the targeted fix for that scenario. It copies the source over the destination whenever MSBuild considers the two different — whether the source is newer or older than the destination, whether the size differs, or the destination is missing — and skips the copy when the destination is unchanged per MSBuild's heuristic.
Under the hood the _CopyDifferingSourceItemsToOutputDirectory target uses the Copy task with SkipUnchangedFiles="true". That "unchanged" check is a heuristic: it compares last-write timestamp and file size only — not a content hash — so a destination that was edited to the same size and timestamp as the source is treated as unchanged and is not re-copied. In practice this restores a mutated destination back to the source version on the next build (the reason people reached for Always) while avoiding the unconditional per-build copy.
Use IfDifferent when:
- A test run or the app itself writes to the copied file (databases, caches, state/storage files, editable config) and you want each build to reset it to the source version.
- You were using
Alwayspurely as a "keep the output in sync with the source" mechanism, not because you truly need a copy on every single build.
<ItemGroup>
<!-- Reset the fixture DB to the source copy whenever it has drifted,
but don't pay a copy on every no-op build. -->
<None Include="fixtures\catalog.db" CopyToOutputDirectory="IfDifferent" />
</ItemGroup>
Globally softening Always with $(SkipUnchangedFilesOnCopyAlways)
If you have an existing codebase full of CopyToOutputDirectory="Always" items and want the performance benefit without editing every item, set the property:
<PropertyGroup>
<SkipUnchangedFilesOnCopyAlways>true</SkipUnchangedFilesOnCopyAlways>
</PropertyGroup>
This makes the _CopyOutOfDateSourceItemsToOutputDirectoryAlways target pass SkipUnchangedFiles="true" to its Copy task, so Always items are only copied when they actually differ — effectively giving Always the same skip-uncha
अक्सर पूछे जाने वाले सवाल
copy मोड क्या हैं?
ये Never, PreserveNewest, Always और IfDifferent हैं, जिनमें IfDifferent नए SDKs में मिलता है।
Always से क्यों बचें?
Always हर build पर कॉपी करता है, भले ही कुछ न बदला हो, जिससे incremental builds धीमे होते हैं।
क्या यह publish output कवर करती है?
हाँ। यह publish copy सेटिंग भी कवर करती है।
जानकारी
लेखक का मूल विवरण
Choosing an MSBuild CopyToOutputDirectory / CopyToPublishDirectory mode: Never, PreserveNewest, Always, and IfDifferent (MSBuild 17.13+), plus $(SkipUnchangedFilesOnCopyAlways). USE FOR: removing the per-build Always copy perf hit; resetting output files mutated between builds. DO NOT USE FOR: general incremental-build diagnosis (use incremental-build); non-MSBuild build systems.
repo: dotnet/skills
लोकप्रियता
- GitHub स्टार
- 5.8k
- रैंकिंग में स्थान
- #14596
- लाइसेंस
- MIT
- अपडेट की गई
- 2/11/2026
कमेंट
- …
इस repository की और skills
create-custom-agent
5.8kयह आपके एजेंट को VS Code के custom agent फ़ाइलें बनाने देती है, जिनके अपने tools, निर्देश और दूसरे agents को handoffs होते हैं।
create-skill
5.8kयह आपके एजेंट को सही नाम, साफ़ trigger विवरण और मानक के अनुसार SKILL.md फ़ाइल वाली नई agent skill बनाने में मदद करती है।
csharp-scripts
5.8kयह आपके एजेंट को .NET command line टूल से एक छोटा C# प्रोग्राम एकल फ़ाइल के रूप में चलाने देती है, पूरा प्रोजेक्ट बनाए बिना।
dotnet-pinvoke
5.8kयह आपके एजेंट को .NET से native C या C++ libraries सही तरीके से कॉल करने में मदद करती है, जिसमें signatures, string संभालना, memory और सुरक्षित handles शामिल हैं।
मिलती-जुलती skills
openclaw-update
394kयह आपके एजेंट को चल रहे OpenClaw Gateway को अपडेट करने में मदद करती है, इंस्टॉल के तरीके के अनुसार सही विधि चुनकर और सेशन बनाए रखकर।
diagnose-gateway
394kयह आपके एजेंट को सेटिंग्स, चैनल और पोर्ट जांचकर पता लगाने देती है कि OpenClaw Gateway क्यों फ़ेल हो रहा है, बिना कुछ बदले।
crabbox-apps
394kयह आपके एजेंट को किसी अस्थायी क्लाउड मशीन पर ऐप खोलने और चलाने देती है, फिर उसका व्यू आपके चैट के साइड पैनल में दिखाती है।