본문으로 건너뛰기
Skillpedia
배포 및 클라우드 (DevOps)5.8k · #14604

msbuild-antipatterns

하는 일

이 스킬은 MSBuild 프로젝트 파일을 흔한 실수 목록과 비교해 검토합니다. 예를 들어 기본 제공 빌드 작업으로 해야 할 셸 명령이 있습니다. 어수선하거나 위험한 프로젝트 파일을 정리하려는 개발자를 위한 스킬입니다.

사용하는 경우

  • ✓.csproj, .props, .targets 파일의 흔한 빌드 실수를 검토하고 싶을 때.
  • ✓프로젝트 파일에 표준 빌드 단계로 바꿀 수 있는 사용자 정의 명령이 많을 때.
  • ✓릴리스 전에 빌드 파일 개선 목록을 우선순위와 함께 받고 싶을 때.

스킬 링크

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

복사해서 AI(Claude, ChatGPT, Cursor)에 붙여넣고 지침을 따르도록 요청하세요.

사용 방법

가장 쉬운 방법입니다. 메시지를 복사해 AI에 붙여넣으세요. AI가 스킬을 읽고 지침을 따릅니다.

바로 붙여넣을 수 있는 메시지

Use this skill to help me: https://github.com/dotnet/skills/blob/main/plugins/dotnet-msbuild/skills/msbuild-antipatterns/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
AI가 이런 스킬을 알아서 찾아 쓰길 원하시나요?무료 Skillpedia MCP를 설치하세요. 한 줄이면 작업마다 스킬 15,000+개 중에서 검색합니다.1분 만에 설치 →

AI에게 요청하는 예시

“제 프로젝트 파일을 검토해서 어떤 MSBuild 습관이 위험한지 알려 주고, 각 항목마다 수정 방법도 알려 주세요.”

매주 새 스킬 5개. 읽는 데 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

자주 묻는 질문

프로젝트를 자동으로 바꾸나요?

아니요. 수정 적용을 요청하지 않는 한 검토는 발견 사항만 제공합니다.

오래된 프로젝트를 변환하는 용도인가요?

아니요. 오래된 프로젝트를 최신 형식으로 바꾸는 일은 현대화 스킬이 다룹니다.

어떤 종류의 실수를 다루나요?

예를 들어 기본 제공 MSBuild 작업이 더 잘 처리하는 일에 Exec를 쓰는 경우가 있습니다.

상세 정보

작성자의 원본 설명

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
업데이트
2026. 11. 2.

이 스킬이 유용한가요?

0

로그인 투표하려면 로그인하세요.

댓글

  • …

이 저장소의 다른 스킬

비슷한 스킬