/msbuild:antipatternsfrom msbuild
Use when changing or reviewing an MSBuild file, covering smells and their fixes
Ships in msbuild. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Review catalog for project and build files, each entry names smell, failure, rule, and a BAD form beside its GOOD form:
OK marks a form to leaveERROR names a build failure, a wrong value, or a wrong outputSTYLE names a form that builds and costs maintenance or timeBC code are BuildCheck diagnosticsmsbuild:diagnostics for the BuildCheck baselinemsbuild:evaluation for the evaluation rule behind an entry[REFERENCES]:
Condition="$(Foo) == net10.0", a comparison side without single quotesMSB4092 on a literal with ., -, ,, or a space, MSB4090 on :, ", or a backtick, MSB4101 on an unclosed quoteMSB4113 in a condition with no operator and MSB4086 in a numeric comparison== and !=BAD:
<Optimize Condition="$(TargetFramework) == net10.0">true</Optimize>
GOOD:
<Optimize Condition="'$(TargetFramework)' == 'net10.0'">true</Optimize>
PropertyGroup-getProperty queryMSB4185, MSBUILDENABLEALLPROPERTYFUNCTIONS=1 enables every property functionBAD:
<GitHead>$([System.IO.File]::ReadAllText('$(MSBuildThisFileDirectory).git/HEAD'))</GitHead>
GOOD:
<Target Name="ReadGitHead" BeforeTargets="CoreCompile">
<ReadLinesFromFile File="$(MSBuildThisFileDirectory).git/HEAD">
<Output TaskParameter="Lines" PropertyName="GitHead" />
</ReadLinesFromFile>
</Target>
Directory.Build.rsp, or an <MSBuild> task can supply-p:$(ToolRoot)bin/ reads /usr/toolbin/ under -p:ToolRoot=/usr/tool_ property, or declare TreatAsLocalProperty on Project when the file wins over the command lineBAD:
<ToolRoot>$([MSBuild]::NormalizeDirectory('$(ToolRoot)'))</ToolRoot>
GOOD:
<_ToolDir>$([MSBuild]::NormalizeDirectory('$(ToolRoot)'))</_ToolDir>
<ToolBin>$(_ToolDir)bin/</ToolBin>
.targets file alone setting a default a .props file or project body reads.targets imports after the project body, every earlier reader sees an empty value.props owns overridable defaults, .targets owns targets and values derived from properties the SDK sets laterBAD in custom.targets:
<ToolVersion>2.0</ToolVersion>
GOOD in custom.props:
<ToolVersion>2.0</ToolVersion>
.props default wrapped in Condition="'$(Name)' == ''" where a project body sets the override.props and win unconditioned, an empty check guards against an environment variable alone.props defaults stay unconditioned, the project assigns another value in its bodyOutputPath and IntermediateOutputPath take no .props default, an assigned value drops the Configuration segmentBaseOutputPath or ArtifactsPath sets the rootBAD in Directory.Build.props:
<Nullable Condition="'$(Nullable)' == ''">enable</Nullable>
GOOD in Directory.Build.props:
<Nullable>enable</Nullable>
.props condition on $(TargetFramework), $(OutputType), an SDK-computed path, or a property the project body sets.props imports before project body and SDK .targets, the condition compares an empty stringTargetFramework as a global property and match, the outer build leaves it emptyDirectory.Build.targets or after the assignment in the projectPackageVersion, and Target conditions are OKBAD in Directory.Build.props:
<PropertyGroup Condition="'$(TargetFramework)' == 'net10.0'">
<DefineConstants>$(DefineConstants);MY_FEATURE</DefineConstants>
</PropertyGroup>
GOOD in Directory.Build.targets:
<PropertyGroup Condition="'$(TargetFramework)' == 'net10.0'">
<DefineConstants>$(DefineConstants);MY_FEATURE</DefineConstants>
</PropertyGroup>
OK in Directory.Packages.props:
<ItemGroup Condition="'$(TargetFramework)' == 'net10.0'">
<PackageVersion Include="Some.Package" Version="10.0.0" />
</ItemGroup>
ArtifactsPath, UseArtifactsOutput, ArtifactsProjectName, BaseIntermediateOutputPath, or MSBuildProjectExtensionsPath in a project fileArtifactsPath and UseArtifactsOutput fail NETSDK1199BaseIntermediateOutputPath warns MSB3539 after restore used the defaultMSBuildProjectExtensionsPath fails MSB3540, the top import read the default and the bottom import reads the body valueArtifactsProjectName reaches bin/ and publish/ while obj/ keeps the project nameArtifactsPivots and output name properties stay project-levelBAD in MyProject.csproj:
<ArtifactsPath>$(MSBuildThisFileDirectory)artifacts</ArtifactsPath>
GOOD in Directory.Build.props:
<ArtifactsPath>$([MSBuild]::NormalizePath('$(MSBuildThisFileDirectory)', 'artifacts'))</ArtifactsPath>
OutputType=Library, EnableDefaultItems=true, RootNamespace equal to the project nameLangVersion at the framework default, or a Directory.Build.props value repeated in a projectLangVersion defaults to 14.0 under net10.0 and 7.3 under netstandard2.0LangVersion appears where the framework default is below what the sources needBAD in MyProject.csproj:
<OutputType>Library</OutputType>
<Nullable>enable</Nullable>
GOOD in a netstandard2.0 analyzer project:
<LangVersion>latest</LangVersion>
NoWarn replacing inherited settings, or a local diagnostic exception in shared build propertiesCoreCompileNoWarn assignments preserve inherited values through $(NoWarn);-p:Name=Value in Directory.Build.rsp, or a project value in Directory.Solution.props-p: switches in the response file are global properties no project overridesDirectory.Solution.props imports into the solution project alone, its properties reach no project under any entry pointDirectory.Build.props, Directory.Build.rsp holds command-line switchesDirectory.Solution.props holds solution project settingsBAD in Directory.Build.rsp:
-p:Configuration=Release
GOOD in Directory.Build.props:
<Configuration Condition="'$(Configuration)' == ''">Release</Configuration>
Update or Remove in Directory.Build.props, an Update matching no item, or an Include of a file the default glob matchesUpdate and Remove act on items that exist at that point, SDK globs import after Directory.Build.propsUpdate or Remove before the globs matches nothing and reports nothingCompile items fail NETSDK1022, a full-path duplicate warns CS2002, a duplicate None copies twice silentlyUpdate and Remove go in the project or Directory.Build.targets, an exclusion goes to DefaultItemExcludes in .propsBAD in Directory.Build.props:
<None Update="appsettings.json" CopyToOutputDirectory="PreserveNewest" />
<Compile Remove="Generated/**" />
GOOD in Directory.Build.props:
<DefaultItemExcludes>$(DefaultItemExcludes);Generated/**</DefaultItemExcludes>
GOOD in Directory.Build.targets:
<None Update="appsettings.json" CopyToOutputDirectory="PreserveNewest" />
Reference with a HintPath into packages/ or another project's bin/, or a host-supplied assembly without Private="false"packages/ for an SDK project, MSB3245Reference items to a project output lose the build order, BC0104Private="false" copy into the output and the host loads that copyPackageReference, projects are ProjectReferenceReference items with HintPath from a property and Private="false"BAD:
<Reference Include="Newtonsoft.Json" HintPath="../packages/Newtonsoft.Json.13.0.3/lib/netstandard2.0/Newtonsoft.Json.dll" />
GOOD:
<PackageReference Include="Newtonsoft.Json" />
OK:
<Reference Include="HostCore" HintPath="$(HostAssemblyDir)HostCore.dll" Private="false" />
Core references Utils, the project references both and names no Utils typeproject.assets.json unless DisableTransitiveProjectReferences is trueBAD:
<ProjectReference Include="../Core/Core.csproj" />
<ProjectReference Include="../Utils/Utils.csproj" />
GOOD:
<ProjectReference Include="../Core/Core.csproj" />
<Import Project="..."> of an optional file without Condition="Exists('...')"MSB4019build/ or buildTransitive/ folder are the package contractBAD:
<Import Project="$(MSBuildThisFileDirectory)eng/custom.props" />
GOOD:
<Import Project="$(MSBuildThisFileDirectory)eng/custom.props" Condition="Exists('$(MSBuildThisFileDirectory)eng/custom.props')" />
OK:
<Project Sdk="Microsoft.NET.Sdk">
AssemblyInfo.cs with an attribute the SDK generates while GenerateAssemblyInfo is trueCS0579AssemblyAttribute itemBAD in Properties/AssemblyInfo.cs:
[assembly: AssemblyTitle("Library")]
GOOD:
<AssemblyTitle>Library</AssemblyTitle>
TargetFramework, both properties in one project, or one value in TargetFrameworksTargetFramework fail NETSDK1046, both together take the singular and report BC0107TargetFrameworks runs an outer and an inner build and adds _net10.0 to the pivot, STYLETargetFramework, a list in TargetFrameworks, the project sets oneBAD:
<TargetFramework>net10.0;netstandard2.0</TargetFramework>
GOOD:
<TargetFrameworks>net10.0;netstandard2.0</TargetFrameworks>
PrepareForBuild error on a ProjectReference outside the layer rootBAD in libs/Library/Library.csproj:
<ProjectReference Include="../../apps/Application/Application.csproj" />
GOOD in Directory.Build.targets:
<Error Condition="'@(_UpwardReference)' != ''" Text="Project '$(MSBuildProjectName)' references outside its layer: @(_UpwardReference, ', ')" />
Inputs and Outputs, or targets combining unrelated workInputs lists every driving file, Outputs lists every written file, the written file joins @(FileWrites) inside the targetBAD:
<Target Name="GenerateBuildInfo" BeforeTargets="CoreCompile">
<Copy SourceFiles="BuildInfo.cs.in" DestinationFiles="$(IntermediateOutputPath)BuildInfo.g.cs" />
</Target>
GOOD:
<Target Name="GenerateBuildInfo" BeforeTargets="CoreCompile" Inputs="BuildInfo.cs.in" Outputs="$(IntermediateOutputPath)BuildInfo.g.cs">
<Copy SourceFiles="BuildInfo.cs.in" DestinationFiles="$(IntermediateOutputPath)BuildInfo.g.cs" />
<ItemGroup>
<FileWrites Include="$(IntermediateOutputPath)BuildInfo.g.cs" />
</ItemGroup>
</Target>
<CallTarget Targets="Compute" />, or an MSBuild call on $(MSBuildProjectFullPath) without Properties, followed by a task reading a value the called target setsDependsOnTargetsBAD:
<Target Name="Report">
<CallTarget Targets="Compute" />
<Message Text="$(Computed)" />
</Target>
GOOD:
<Target Name="Report" DependsOnTargets="Compute">
<Message Text="$(Computed)" />
</Target>
Copy or Move into $(OutDir), $(OutputPath), $(TargetDir), $(BaseOutputPath), or $(PublishDir), or a target taking an SDK Before or After target name in a .csproj or .props fileCopy in a custom target reaches the project's own output, a referencing project and dotnet publish receive nothingNone or Content items with CopyToOutputDirectory or CopyToPublishDirectory, a custom step attaches with AfterTargetsBAD:
<Target Name="AfterBuild">
<Copy SourceFiles="settings.ini" DestinationFolder="$(OutDir)" />
</Target>
GOOD:
<None Update="settings.ini" CopyToOutputDirectory="PreserveNewest" />
WriteLinesToFile without Overwrite="true" and WriteOnlyWhenDifferent="true"Lines per buildOverwrite="true" and WriteOnlyWhenDifferent="true", the timestamp then holds for the next incremental checkOutputs, are OKBAD:
<WriteLinesToFile File="$(IntermediateOutputPath)version.txt" Lines="$(Version)" />
GOOD:
<WriteLinesToFile File="$(IntermediateOutputPath)version.txt" Lines="$(Version)" Overwrite="true" WriteOnlyWhenDifferent="true" />
Copy with DestinationFolder over a recursive glob%(RecursiveDir) into DestinationFilesBAD:
<Copy SourceFiles="@(Asset)" DestinationFolder="$(OutDir)assets/" />
GOOD:
<Copy SourceFiles="@(Asset)" DestinationFiles="@(Asset->'$(OutDir)assets/%(RecursiveDir)%(Filename)%(Extension)')" />
C:\tools\, D:\packages\, or /usr/local/bin/ in a project fileMSB4019 or MSB3245$(MSBuildThisFileDirectory) or $(MSBuildProjectDirectory) with NormalizeDirectory or NormalizePathBAD:
<ToolPath>C:\tools\mytool\mytool.exe</ToolPath>
GOOD:
<ToolPath>$([MSBuild]::NormalizePath('$(MSBuildThisFileDirectory)', 'tools', 'mytool'))</ToolPath>
\ to / in a value whose first segment exists on disk, an item passed to a task converts in every caseExec commands starting with a program name reach sh unconverted/ in every path| [INDEX] | [PLACE] | [SEVERITY] | [RESULT] |
|---|---|---|---|
| [01] | Exec command | ERROR | sh deletes it, cat data\file.txt reads datafile.txt |
| [02] | Lines on WriteLinesToFile | ERROR | Every item converts, the file receives a/b for a\b |
| [03] | Custom task passing a path to file APIs | ERROR | No conversion inside the task |
| [04] | Import, item glob, Copy, MakeDir, or Delete path | STYLE | Converts |
| [05] | $(MSBuildThisFileDirectory)tools/mytool | OK | Reserved directory property ends with the host separator |
BAD:
<Exec Command="cat data\file.txt" />
GOOD:
<Exec Command="cat data/file.txt" />
Exec running mkdir, copy, del, xcopy, touch, or echo text > fileExec with ConsoleToMSBuild running sed or powershell -c for a string or path value$(MSBuildThisFileDirectory) first| [INDEX] | [COMMAND] | [TASK] |
|---|---|---|
| [01] | mkdir, md | MakeDir |
| [02] | copy, cp, xcopy, robocopy | Copy |
| [03] | del, erase, rm | Delete |
| [04] | rmdir, rd | RemoveDir |
| [05] | move, mv | Move |
| [06] | echo text > file | WriteLinesToFile |
| [07] | touch | Touch |
BAD:
<Exec Command="mkdir $(OutDir)logs" />
<Exec Command="echo $(Version) | sed 's/-preview//'" ConsoleToMSBuild="true">
<Output TaskParameter="ConsoleOutput" PropertyName="CleanVersion" />
</Exec>
GOOD:
<MakeDir Directories="$(OutDir)logs" />
<CleanVersion>$(Version.Replace('-preview', ''))</CleanVersion>
<Exec Command="chmod +x ..." /> or <Exec Command="cmd /c ..." /> without an operating system condition$([MSBuild]::IsOSPlatform('...'))BAD:
<Target Name="MakeExecutable" AfterTargets="Build">
<Exec Command="chmod +x $(OutDir)mytool" />
</Target>
GOOD:
<Target Name="MakeExecutable" AfterTargets="Build" Condition="!$([MSBuild]::IsOSPlatform('Windows'))">
<Exec Command="chmod +x $(OutDir)mytool" />
</Target>
<Exec Command="dotnet build ..." />, dotnet msbuild, pack, publish, restore, test, run, or msbuild inside a target-check reports BC0302ProjectReference with ReferenceOutputAssembly="false", call a target through the MSBuild taskBAD:
<Target Name="BuildTool" BeforeTargets="Build">
<Exec Command="dotnet build ../Tool/Tool.csproj -c $(Configuration)" />
</Target>
GOOD:
<ProjectReference Include="../Tool/Tool.csproj" ReferenceOutputAssembly="false" />
Repeated evaluations of one project outside restore share the output paths.
<MSBuild> call's Properties or an item's AdditionalProperties with a value the target project's output path lacks (_IsPublishing=true)(project, {_IsPublishing=true}) beside (project, {})bin/ and obj/, CoreCompile runs twice-check reports BC0102 for the copies and BC0202 for the _IsPublishing read, a parallel build can report MSB3026ArtifactsPivots beside a property the build needs, Configuration, TargetFramework, and RuntimeIdentifier already pivot the output pathPublish in the same instance through DependsOnTargets'$(_IsPublishing)' == '', no condition fails dotnet publish with MSB4006, a != 'true' read reports BC0201_IsPublishing to the SDK, a build under _IsPublishing=true with PublishRuntimeIdentifier set moves to that runtime's output pathBAD:
<Target Name="PublishOnBuild" AfterTargets="Build" Condition="'$(_IsPublishing)' == ''">
<MSBuild Projects="$(MSBuildProjectFullPath)" Targets="Publish" Properties="_IsPublishing=true" />
</Target>
GOOD:
<Target Name="PublishOnBuild" AfterTargets="Build" DependsOnTargets="Publish" Condition="'$(_IsPublishing)' == ''" />
ProjectReference with SetTargetFramework="TargetFramework=net10.0" to a project declaring <TargetFramework>net10.0</TargetFramework>SetTargetFramework creates instance (project, {TargetFramework=net10.0}) beside the solution's (project, {})bin/Debug/net10.0/ and obj/Debug/net10.0/ProjectReference protocol removes TargetFramework for a single-targeting reference, SetTargetFramework reintroduces itSetTargetFramework, a multi-targeting reference or a build under another framework takes itSkipGetTargetFrameworkProperties="true" with UndefineProperties="TargetFramework" or SetTargetFrameworkBAD:
<ProjectReference Include="../Tool/Tool.csproj" SetTargetFramework="TargetFramework=net10.0" />
GOOD:
<ProjectReference Include="../Tool/Tool.csproj" />
OK:
<ProjectReference Include="../Tool/Tool.csproj" SkipGetTargetFrameworkProperties="true" UndefineProperties="TargetFramework" ReferenceOutputAssembly="false" />
What SKILL.md sets; muted values are Claude Code's defaults
Other plugins' skills for the same job
npx claudepluginhub bsamiee/rasm --plugin msbuild5 skills in this plugin
/diagnosticsUse when diagnosing a .NET build, covering binary log capture and analysis/evaluationUse when writing or diagnosing an MSBuild declaration, covering the evaluation phase/executionUse when writing or ordering an MSBuild target, covering the execution phase/packagingUse when changing NuGet configuration, package references, or a .slnx, covering package management and NU codes