.NET project file analyzers community

Proj0212: Define the project icon file explicitly

To ensure the creation of well-formed NuGet packages and for maximum compatibility with external tools, explicitly define the <PackageIcon> node or disable package generation by defining the <IsPackable> node with value false.

While in principle only defining <PackageIcon> should be enough, not all external tools are capable of correctly handling this modern type of package icon definition. Similarly, while <PackageIconUrl> is deprecated, some older tools can not correctly handle the modern option. For maximum compatibility it is therefore recommended to define both.

Non-compliant

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

  <PropertyGroup>
    <TargetFramework>net8.0</TargetFramework>
    <IsPackable>true</IsPackable>
  </PropertyGroup>

</Project>

Compliant

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

  <PropertyGroup>
    <TargetFramework>net8.0</TargetFramework>
    <IsPackable>true</IsPackable>
    <PackageIcon>logo_128x128.png</PackageIcon>
  </PropertyGroup>

  <ItemGroup>
    <None Include="..\..\design\logo_128x128.png" Pack="true" PackagePath="\" />
  </ItemGroup>

</Project>

Or disable packability:

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

  <PropertyGroup>
    <TargetFramework>net8.0</TargetFramework>
    <IsPackable>false</IsPackable>
  </PropertyGroup>

</Project>