Pular para o conteúdo
Skillpedia
Deploy e nuvem (DevOps)5,8 mil · #14604

msbuild-antipatterns

O que ela faz

Esta skill revisa arquivos de projeto do MSBuild com base em uma lista de erros comuns, como comandos de shell que deveriam ser tarefas nativas do build. É para desenvolvedores que querem limpar arquivos de projeto bagunçados ou arriscados.

Quando usar

  • ✓Quando você quer revisar um arquivo .csproj, .props ou .targets quanto a erros comuns de build.
  • ✓Quando um arquivo de projeto tem muitos comandos personalizados que poderiam ser etapas padrão do build.
  • ✓Quando você quer uma lista priorizada de melhorias nos arquivos de build antes de um lançamento.

Link da skill

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

Copie e cole na sua IA (Claude, ChatGPT ou Cursor) pedindo para seguir as instruções.

Como usar

O jeito mais fácil: copie a mensagem e cole na sua IA. Ela lê a skill e segue as instruções.

Mensagem pronta para colar

Use esta skill para me ajudar: https://github.com/dotnet/skills/blob/main/plugins/dotnet-msbuild/skills/msbuild-antipatterns/SKILL.md Leia o arquivo SKILL.md desse link e siga as instruções dele na minha tarefa.
Quer que a sua IA encontre skills como esta sozinha?Instale o MCP grátis do Skillpedia: uma linha, e ela pesquisa entre 15.000+ skills antes de cada tarefa.Instalar em 1 minuto →

Exemplo do que pedir para a IA

“Revise meu arquivo de projeto e me diga quais hábitos do MSBuild são arriscados, com uma correção para cada um.”

5 skills novas por semana. 1 minuto de leitura.

Como funciona

O agente lê o arquivo, compara cada parte com seu catálogo de erros conhecidos e devolve achados priorizados com a correção de cada um.

Conteúdo técnico (SKILL.md original)

Texto original do autor, em inglês, direto do 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

Perguntas frequentes

Ela muda meu projeto automaticamente?

Não. Uma revisão devolve apenas os achados, a menos que você peça para aplicar as correções.

Serve para converter projetos antigos?

Não. A conversão de projetos antigos para o formato mais novo é coberta pela skill de modernização.

Que tipos de erro ela cobre?

Por exemplo, o uso de Exec para trabalhos que as tarefas nativas do MSBuild resolvem melhor.

Detalhes

Descrição original do autor

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

Popularidade

Estrelas no GitHub
5,8 mil
Posição no ranking
#14604
Licença
MIT
Atualizada em
02/11/2026

Essa skill é útil?

0

Entre para votar.

Comentários

  • …

Mais skills deste repositório

Skills parecidas