Really just echoing others. We just returned from our trip to Italy. The Vatican has a published dress code to cover knees and shoulders. I saw many people inside the Vatican museums who were clearly violating the dress code. I don't know if they just slipped through or if they removed scarves/sarongs after they got inside. Regardless, I wouldn't risk being turned away nor would I choose to violate their clear rules.
However, at less visited churches (church in Tellaro, on Murano, and San Clemente in Rome), I saw no posted dress code at the actual site--and I looked at the doorways before entering--and either there was no one present to check attire or the people working clearly did not care what tourists were wearing. San Clemente's website requests "appropriately modest attire." I saw many men and teenage boys in long shorts that came to the top of their knees but did not cover them. I'm not sure where the "rule" about covering knees comes from if the church itself does not post it.
As far as showing respect as you would in your own church, I haven't attended a church in decades that would frown on people attending in long shorts. My French neighbor, who visits Europe nearly every summer, advised before our trip that my thirteen year old son would be fine in long shorts everywhere except the Vatican. That was consistent with my observations while in Italy. Since he wears shorts even when it is 50 degrees F, I had no interest in making him wear long pants when it was over 80 out and it wasn't necessary--especially when we just looked inside a church for ten minutes out of a full day of other activities.