.NET project file analyzers community

Proj0451: Test projects should not be publishable

Test projects should only be responsible for running tests. Hence if they can be published, that is most likely unintended, and wrong.

Non-compliant

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

  <PropertyGroup>
    <TargetFramework>net8.0</TargetFramework>
    <IsTestProject>true</IsTestProject>
    <IsPublishable>true</IsPublishable>
  </PropertyGroup>

  <ItemGroup Label="Build tools">
    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.0" PrivateAssets="all" />
  </ItemGroup>
  
</Project>

Compliant

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

  <PropertyGroup>
    <TargetFramework>net8.0</TargetFramework>
    <IsTestProject>true</IsTestProject>
    <IsPublishable>false</IsPublishable>
  </PropertyGroup>

  <ItemGroup Label="Build tools">
    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.0" PrivateAssets="all" />
  </ItemGroup>
  
</Project>