It is only my opinion, but if the temperatures are as high as when I was in Italy a couple of weeks ago 105F and muggy) I will not to wear long pants, and there is no way I would carry a pair of long pants in a bag or backpack just for the hour or less I need to enter the Basilica. There are no changing rooms in the Basilica, it is not a Walmart or Target store. So keep your shorts and dress, and just carry a pareo wrap in a purse (for women) and a pair of knee support sleeves if your shorts are too much above the knee.
Below is a photo I found online about the interior of St. Peter’s Basilica at the Vatican in summer. The basilica at the Vatican has by far the stricter dress code and checks. Look at what people are wearing and that will give you an idea with what is acceptable to wear.
https://www.alamy.com/rome-italy-july-2017-tourists-inside-st-peters-basilica-in-st-peters-image152521018.html
The image below is another example of tourists wearing shorts, this time inside the Basilica of San Marco in Venice.
https://share.google/pos3YT8p9oM7C11Nm
Use the above examples as a guideline on what you can wear without Knee sleeves or pareo wraps.