मुख्य सामग्री पर जाएँ
Skillpedia
डिप्लॉय और क्लाउड (DevOps)5.8k · #14604

msbuild-antipatterns

यह क्या करती है

यह स्किल MSBuild project फ़ाइलों की समीक्षा आम गलतियों की सूची से करती है, जैसे ऐसे shell कमांड जो बिल्ट-इन tasks से हो सकते थे। यह उन डेवलपर के लिए है जो उलझी या जोखिम भरी project फ़ाइलें साफ़ करना चाहते हैं।

कब इस्तेमाल करें

  • ✓जब आप .csproj, .props या .targets फ़ाइल में आम build गलतियाँ जाँचना चाहें।
  • ✓जब किसी project फ़ाइल में ऐसे बहुत सारे custom कमांड हों जो मानक build चरण बन सकते हों।
  • ✓जब आप release से पहले build फ़ाइलों में सुधारों की प्राथमिकता वाली सूची चाहें।

Skill का लिंक

https://github.com/dotnet/skills/blob/main/plugins/dotnet-msbuild/skills/msbuild-antipatterns/SKILL.md

इसे कॉपी करके अपने AI (Claude, ChatGPT या Cursor) में पेस्ट करें और निर्देशों का पालन करने को कहें।

कैसे इस्तेमाल करें

सबसे आसान तरीका: मैसेज कॉपी करके अपने AI में पेस्ट करें। वह skill पढ़कर निर्देशों का पालन करेगा।

पेस्ट करने के लिए तैयार मैसेज

इस skill से मेरी मदद करो: https://github.com/dotnet/skills/blob/main/plugins/dotnet-msbuild/skills/msbuild-antipatterns/SKILL.md इस लिंक की SKILL.md फ़ाइल पढ़ो और मेरे काम में उसके निर्देशों का पालन करो।
क्या आप चाहते हैं कि आपका AI ऐसी skills खुद ढूँढे?मुफ़्त Skillpedia MCP इंस्टॉल करें: बस एक लाइन, और हर काम से पहले यह 15,000+ skills में खोजता है।1 मिनट में इंस्टॉल करें →

AI से क्या माँगें: उदाहरण

“मेरी project फ़ाइल की समीक्षा कीजिए और बताइए कि कौन सी MSBuild आदतें जोखिम भरी हैं, हर एक के सुधार के साथ।”

हर हफ़्ते 5 नई skills, 1 मिनट में पढ़ें।

यह कैसे काम करती है

एजेंट फ़ाइल पढ़ता है, हर हिस्से को ज्ञात गलतियों की अपनी सूची से मिलाता है, और हर एक के सुधार के साथ प्राथमिकता वाले निष्कर्ष लौटाता है।

तकनीकी सामग्री (मूल SKILL.md)

लेखक का मूल टेक्स्ट, अंग्रेज़ी में, सीधे GitHub से।

MSBuild Anti-Pattern Catalog

A numbered catalog of common MSBuild anti-patterns. Each entry follows the format:

  • Smell: What to look for
  • Why it's bad: Impact on builds, maintainability, or correctness
  • Fix: Concrete transformation

Use this catalog when scanning project files for improvements.

Review output contract

For review, audit, maintainability, or correctness-risk requests:

  1. Do not edit files unless the user explicitly asks for fixes.
  2. Return prioritized findings grounded in the supplied file, with impact and a targeted recommendation.
  3. Separate confirmed defects from conditional risks and already-correct patterns.
  4. Keep the final answer as the review; do not replace it with a terse summary of changes.

AP-01: <Exec> for Operations That Have Built-in Tasks

Smell: <Exec Command="mkdir ..." />, <Exec Command="copy ..." />, <Exec Command="del ..." />

Why it's bad: Built-in tasks are cross-platform, support incremental build, emit structured logging, and handle errors consistently. <Exec> is opaque to MSBuild.

<!-- BAD -->
<Target Name="PrepareOutput">
  <Exec Command="mkdir $(OutputPath)logs" />
  <Exec Command="copy config.json $(OutputPath)" />
  <Exec Command="del $(IntermediateOutputPath)*.tmp" />
</Target>

<!-- GOOD -->
<Target Name="PrepareOutput">
  <MakeDir Directories="$(OutputPath)logs" />
  <Copy SourceFiles="config.json" DestinationFolder="$(OutputPath)" />
  <Delete Files="@(TempFiles)" />
</Target>

Built-in task alternatives:

Shell Command MSBuild Task
mkdir <MakeDir>
copy / cp <Copy>
del / rm <Delete>
move / mv <Move>
echo text > file <WriteLinesToFile>
touch <Touch>
xcopy /s <Copy> with item globs

AP-02: Unquoted Condition Expressions

Smell: Condition="$(Foo) == Bar" — either side of a comparison is unquoted.

Why it's bad: If the property is empty or contains spaces/special characters, the condition evaluates incorrectly or throws a parse error. MSBuild requires single-quoted strings for reliable comparisons.

<!-- BAD -->
<PropertyGroup Condition="$(Configuration) == Release">
  <Optimize>true</Optimize>
</PropertyGroup>

<!-- GOOD -->
<PropertyGroup Condition="'$(Configuration)' == 'Release'">
  <Optimize>true</Optimize>
</PropertyGroup>

Rule: Always quote both sides of == and != comparisons with single quotes.


AP-03: Hardcoded Absolute Paths

Smell: Paths like C:\tools\, D:\packages\, /usr/local/bin/ in project files.

Why it's bad: Breaks on other machines, CI environments, and other operating systems. Not relocatable.

<!-- BAD -->
<PropertyGroup>
  <ToolPath>C:\tools\mytool\mytool.exe</ToolPath>
</PropertyGroup>
<Import Project="C:\repos\shared\common.props" />

<!-- GOOD -->
<PropertyGroup>
  <ToolPath>$(MSBuildThisFileDirectory)tools\mytool\mytool.exe</ToolPath>
</PropertyGroup>
<Import Project="$(RepoRoot)eng\common.props" />

Preferred path properties:

Property Meaning
$(MSBuildThisFileDirectory) Directory of the current .props/.targets file
$(MSBuildProjectDirectory) Directory of the .csproj
$([MSBuild]::GetDirectoryNameOfFileAbove(...)) Walk up to find a marker file
$([MSBuild]::NormalizePath(...)) Combine and normalize path segments

AP-04: Restating SDK Defaults

Smell: Properties set to values that the .NET SDK already provides by default.

Why it's bad: Adds noise, hides intentional overrides, and makes it harder to identify what's actually customized. When defaults change in newer SDKs, the redundant properties may silently pin old behavior.

<!-- BAD: All of these are already the default -->
<PropertyGroup>
  <OutputType>Library</OutputType>
  <EnableDefaultItems>true</EnableDefaultItems>
  <EnableDefaultCompileItems>true</EnableDefaultCompileItems>
  <RootNamespace>MyLib</RootNamespace>       <!-- matches project name -->
  <AssemblyName>MyLib</AssemblyName>         <!-- matches project name -->
  <AppendTargetFrameworkToOutputPath>true</AppendTargetFrameworkToOutputPath>
</PropertyGroup>

<!-- GOOD: Only non-default values -->
<PropertyGroup>
  <TargetFramework>net8.0</TargetFramework>
</PropertyGroup>

AP-05: Manual File Listing in SDK-Style Projects

Smell: <Compile Include="File1.cs" />, `<Compile Inc

अक्सर पूछे जाने वाले सवाल

क्या यह मेरा प्रोजेक्ट अपने-आप बदलेगी?

नहीं। समीक्षा सिर्फ़ निष्कर्ष देती है, जब तक आप सुधार लागू करने को न कहें।

क्या यह पुराने प्रोजेक्ट बदलने के लिए है?

नहीं। पुराने प्रोजेक्ट को नए फ़ॉर्मैट में बदलना modernization स्किल कवर करती है।

यह किस तरह की गलतियाँ कवर करती है?

उदाहरण के लिए, ऐसे काम के लिए Exec इस्तेमाल करना जिसे बिल्ट-इन MSBuild tasks बेहतर संभालते हैं।

जानकारी

लेखक का मूल विवरण

DO NOT INVOKE when the primary request explicitly asks to convert, migrate, modernize, or rewrite a legacy/old-style project to SDK style; use msbuild-modernization. Migration prompts often mention ToolsVersion, explicit Compile/Reference entries, packages.config, or Microsoft.CSharp.targets, but merely reviewing or auditing a file that contains those patterns remains in scope here. USE FOR broad review, audit, lint, or maintainability/correctness checks of project/build files, including custom targets; prioritized cross-cutting findings; discrete anti-patterns; F# ordering/FS0039; cross-platf

repo: dotnet/skills

लोकप्रियता

GitHub स्टार
5.8k
रैंकिंग में स्थान
#14604
लाइसेंस
MIT
अपडेट की गई
2/11/2026

क्या यह skill काम की है?

0

लॉग इन करें वोट करने के लिए।

कमेंट

  • …

इस repository की और skills

मिलती-जुलती skills