Proj0052: Prefer attributes over elements

The use of XML attributes is preferred over child XML elements for item metadata within MSBuild files. Attributes are more concise and easier to scan than nested elements, especially when configuring only a few metadata properties. This style also aligns with modern .NET SDK project conventions.

Exceptions

  • Structural Containers <PropertyGroup> and <ItemDefinitionGroup> are excluded from this rule, as they are designed by MSBuild to use child elements rather than attributes.
  • Content item metadata containing multi-line text is automatically recognized and will not be flagged, as XML attributes are unable to properly preserve line breaks.

Non-compliant

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>net10.0</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Qowaiv">
      <Version>8.0.0</Version>
    </PackageReference>
  </ItemGroup>

</Project>

Compliant

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>net10.0</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Qowaiv" Version="8.0.0" />
  </ItemGroup>

</Project>