Monday, January 20, 2020

How to list installed .NET Framework versions using PowerShell

Getting installed .NET Framework versions is (surprisingly) not a simple task. On this post, let's try to address that.

When .NET developers have to fix problems on a remote server that requires knowing which versions of the .NET Framework are installed, they'll be frustrated. Unfortunately, the Redmond folks made it unnecessarily complicated to know the installed versions of the .NET Framework on a  Windows box.

.NET Core on the other side, does it well via the .NET Core CLI. But for those of us still on the .NET Framework, what can we do? The official documentation, describes multiple options including accessing the registry, using PowerShell and building a C# application.

Listing the installed folders

The simplest and fastest solution is obviously listing the contents of the folders .NETFramework folder with:
dir "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework"
While that's usually sufficient to list what's installed, it does not confirm IF the frameworks are correctly registered in the system. To confirm that everything's correctly setup we'll have to use PowerShell as described next.

Listing the frameworks using PowerShell

To list which frameworks are installed directly from the Windows Registry can be found on this PowerShell script:

Simplifying Further

Ok, but let's assume that we're on a remote server. Opening chrome and downloading this script might not be ideal. Could we somehow script this out? Yes, by using PowerShell's Invoke-WebRequest (PowerShell's curl), we could make it a one-liner so that we don't have to even open a browser and download that script from GitHub. Here is it:
Invoke-WebRequest -Uri https://github.com/hd9/powershell/raw/master/list-dotnet-frameworks.ps1 -OutFile list-dotnet-frameworks.ps1; .\list-dotnet-frameworks.ps1
Hope it helps!

See Also

For more posts on .NET Core, please click here.

About the Author

Bruno Hildenbrand      
Principal Architect, HildenCo Solutions.