Skip to main content
GameDev.net gamedev.net
🔒 Locked

[.net] Checking for .NET framework installation

Started by gellin Aug 27, 2006 at 2:20 PM 7 replies 1.1k views
Original Post
gellin
gellin
Well since all the programs I write in C# require the .NET 2.0 framework, I was wondering what is the best way to have your application check to make sure that the user has it installed. Thanks
jteeuwen
jteeuwen
Use System.Environment.Version.Major.

Doing this on my machine:
Console.WriteLine( System.Environment.Version);


shows: '2.0.50727.42'.

Note that System.Environment.Version is available in both the 1.1 and 2.0 framework.

One thing to note though. A Program compiled for the 2.0 Framework will most likely not even run with anything less than the 2.0 runtime installed. So it's really a non-issue. If the program doesn't run, the user either has a version <2.0 or no framework at all. He will have to install the 2.0 runtime either way.

If you really want to handle all these situations elegantly. write a seperate launcher program in c/c++ or anything that does not require the .NET framework.
Have that launcher check if a framework version is present on the user's system.

I've been googling a bit to see how this can be done. Havn't really found a programmable way to do so, but you may have some success by simply trying to launch the .NET app from the launcher. If it fails, the shell should return a non-zero exit code. This means Some error occured and it most likely means there is either an incorrect version, or no framework at all on the users system.
regards, Jim--------------------------------.: moo :.
RipTorn
RipTorn
You cannot run an .net app if there is no .net, so doing a check on Environment.Version isn't always going to be an option.

You could write a small unmanaged program that checks the registry for the following:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\v1.1.4322
or
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\v2.0.50727

It will have a key called 'Install' set to '1' if it is installed.


Or... you can use clickonce, and let it do the hard work (including downloading and installing the framework) for you.
jfclavette
jfclavette
You could package your application in an installer that does all this for you.
I teleported home one night; With Ron and Sid and Meg; Ron stole Meggie's heart away; And I got Sydney's leg. <> I'm blogging, emo style
gellin
gellin
Thanks for your help guys. I just found under the setup properties a prerequisites button. In there I can check .NET framework 2.0 and if the installer doesn't find it, it's supposed to go download it for you off of the internet.
RipTorn
RipTorn
Quote:
Original post by gellin
Thanks for your help guys. I just found under the setup properties a prerequisites button. In there I can check .NET framework 2.0 and if the installer doesn't find it, it's supposed to go download it for you off of the internet.


This is the clickonce publishing setup. It is not automatically part of the .exe. Hence the 'publish now' button, etc.
philprice
philprice
If .NET assemblies are built with a version greater than the version(s) of the framework/runtime currently installed, they will prompt saying that they can't run.
RipTorn
RipTorn
Quote:
Original post by philprice
If .NET assemblies are built with a version greater than the version(s) of the framework/runtime currently installed, they will prompt saying that they can't run.


However, if no .net framework is installed at all, windows will say it is not a valid win32 application.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.