Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programatically check for version .NET Framework - Should I?

I got at task to extend en existing WinForm application to make a check weather or not the required .NET Framework (fx. 3.5) is installed.

Well the issues is that - if there is no .NET Framework installed, the winform program is not able to run at all... I assume.

I could (maybe) do like suggested here: (and make a c++ program that should start first, make the check and then launch the application) Check on .Net framework version from WinForms app But I would rather not go into c++.

Another way seems to be this solution: Why isn't an exception thrown when the right .NET framework version is not present? ... where you configure your application in app.config. But I doubt that will work if there i no .NET framework installed.

<startup>
    <supportedRuntime version="v3.5" />
</startup>

So my question is what is Best Practice in this area? Should I make the check one way or the other, or should I just make it a pre-requisite, that fx. .NET Framework version 3.5 is demanded?

like image 424
Jan Avatar asked Apr 24 '14 12:04

Jan


People also ask

Which version of .NET Framework should I use?

A cross-platform and open-source framework, . NET Core is best when developing applications on any platform. . NET Core is used for cloud applications or refactoring large enterprise applications into microservices. You should use .

How do you check if .NET Framework is up to date?

Use Registry Editor The installed security updates and hotfixes for each version of the . NET Framework installed on a computer are listed in the Windows registry. You can use the Registry Editor (regedit.exe) program to view this information. , then select Run.

How do you check if .NET Framework is working?

Open Start. Search for PowerShell, right-click the top result, and select the Run as administrator option. Type the following command to check the version of . NET installed and press Enter: Get-ChildItem 'HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP' -Recurse | Get-ItemProperty -Name version -EA 0 | Where { $_.


1 Answers

If the required framework is not installed, your application won't run, so checking if the framework is installed from within your app is checking something you already know to be true.

If you want to check that the framework is installed, you really need to do this from within a a bootstrapper exe either written in a .NET version you know will exist (like .NET 2 as it gets installed on the machine with the OS) or some other language like C++.

You can check in the registry (HKLM\SOFTWARE\Microsoft\NET Framework Setup\NDP) to see what frameworks are installed. This can easily be done in C# or any other language.

C# code something like this:

var baseKeyName = @"SOFTWARE\Microsoft\NET Framework Setup\NDP";
var installedFrameworkVersions = Registry.LocalMachine.OpenSubKey(baseKeyName);

var versionNames = installedFrameworkVersions.GetSubKeyNames();
like image 131
Simon Clough Avatar answered Oct 28 '22 00:10

Simon Clough