I had the same issue when running dotnet publish for multiple platforms using a bash script (Windows / MacOS). In my case, the fix turned out to be running dotnet clean before the publish.
dotnet publish
dotnet clean