Sorry for the late reply. You likely need to add some additional settings to your .csproj or to the respective .props files, to target the correct platform configuration for releases, such as
<PropertyGroup>
<DefineConstants>$(DefineConstants);RELEASE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PublishTrimmed>True</PublishTrimmed>
</PropertyGroup>
However, I would recommend doing these things in a build pipeline instead of building a release locally. I was planning to write a follow up on this, but didn't find the time yet.