3

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.

Racoon
  • 951
  • 3
  • 14
  • 32
  • 2
    You are asking if it is possible for a C# program to check if it is possible to run C# programs? 'I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question.' – Joren Nov 27 '09 at 16:19
  • Let's assume he's asking "How to pack a .NET executable inside a native one which checks if .NET is installed before launching its contents?". – CannibalSmith Nov 27 '09 at 16:25

4 Answers4

10

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.

Community
  • 1
  • 1
brendan
  • 29,308
  • 20
  • 68
  • 109
4

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
  • 134,786
  • 31
  • 255
  • 325
4

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 Gabriel Himango
  • 58,906
  • 38
  • 158
  • 212
1

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

Yuriy Faktorovich
  • 67,283
  • 14
  • 105
  • 142