.NET project file analyzers community

Proj0028: Define conditions on level 1

MS Build files can contain conditionals. By setting those conditions only on container nodes on level 1 (such as <PropertyGroup> and <ItemGroup>), readability is improved. As a bonus, conditional configuration is automatically grouped. Note that Choose/When is ignored by this rule.

Non-compliant

<Project>
  
  <PropertyGroup>
    <TargetFramework>net8.0</TargetFramework>
	<GeneratePackageOnBuild  Condition="'$(Configuration)'=='Release'">true</GeneratePackageOnBuild>
  </PropertyGroup>
  
</Project>

Compliant

<Project>
  
  <PropertyGroup>
    <TargetFramework>net8.0</TargetFramework>
  </PropertyGroup>
  
  <PropertyGroup Condition="'$(Configuration)'=='Release'">
    <GeneratePackageOnBuild>true</GeneratePackageOnBuild>
  </PropertyGroup>
</Project>