tags:

views:

173

answers:

4

Hi. There are several options for C#-based programs to determine which .Net version is installed. But is it possible to determine if .Net IS installed? I mean if I run C#-program on a machine without any .Net installed, I get the following error:


Myprogram.exe - Application Error

The application failed to initialize properly (0xc0000135). Click on OK to terminate the application.

OK

Yes, I can write a wrapper (some external program or msi-package or somethins like that) but I'm wondering if I can do this sanity check from my C#-program? All I want is to check .Net existence and exit on failure with correct warning like "Microsoft .Net is required. Please install it bla-bla-bla".

Any clue? Thanks.

+4  A: 

If you create a ClickOnce installer and add the .NEt version you need as a prerequisite, then this check will be done for you when your users install your program for the first time.

ChrisF
Good idea, thanks!
Racoon
+10  A: 

I think the preferred way to do this is to create an installer for your app and make the .Net Framework a pre-req that the installer checks for.

You can also include the .Net Framework re-distributable components so your installer will install it if it is not found.

See this question for more info.

brendan
I concur! +1. I think this is the correct way to do it.
J Angwenyi
Thanks, I tried to avoid it but... Well, be it.
Racoon
+1  A: 

You can use Bootstrapper Plug-in and the framework will be bundled with your application.

Yuriy Faktorovich
Sound interesting. Thanks!
Racoon
+4  A: 

No, C# cannot check for the existence of .NET. It's like asking if you can write a program to check if the computer is turned on.

You'd need to write native code to check this, or more preferably, an installer that checks this.

Judah Himango
It seems I have nothing to do except this. Thanks.
Racoon
"It's like asking if you can write a program to check if the computer is turned on." made me lol but it's a great example :D
Patonza