Fixes https://github.com/dotnet/aspnetcore/issues/59291 which was fixed by https://github.com/dotnet/sdk/pull/48224 on 10.0.x but was not backported.