This turned out to be nothing to do wiht project B. There was a project C which both B referenced. It was originally a .NET Framework 4.7.2 project and was upgraded to .NET8 using Visual Studio upgrade tool.
Creating a new .NET8 library project and moving the files in along with updating for any required .NET changes resolved the issue.