Test projects should only be responsible for running tests. Hence if they can be published, that is most likely unintended, and wrong.
<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>
<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>