Detect Microsoft .Net Framework versions

I use the following code to determine which specific version of the Microsoft .Net Framework 4.0 is installed on my SQL Server. It detects versions from 4.5 to 4.7, and can be easily extended as new versions are release by adding new rows to the #NetFrameworkVersions table. Be aware, if you run this on a server that does not have at least version 4.5, you’ll see no results.

The code in this post is based upon the details provided by Microsoft here.