Reproduction steps:
1. Open the attached project “URP_and_HDRP”
2. In Navigation Bar go to File → Build Settings
3. Click on Build and select an empty folder
4. Observe the compilation process
Expected result: During the building process, the project is built with a reasonable shader variants count
Actual result: During the building process, there are moments where the shader variants count gets to 25000 and above
Reproducible with: 2020.3.44f1, 2021.3.18f1, 2022.2.5f1, 2023.1.0b5, 2023.2.0a3
Reproducible on: Windows 10
Note: Quality settings need to be sorted so the RPAsset used are all from URP or HDRP. This is mandatory for 2022 and later versions.
If All Quality levels are checked in 2021.3 and earlier versions, everything works as expected.