Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Checking for .NET dependencies before launching

Tags:

.net

xna

I have several apps that I work on and like to distribute to friends that require Microsoft Provided .dlls and or frameworks. Specifically, XNA. I'm tired of getting emails back from them saying "It crashed" when in reality, all that's happened is they don't have XNA (or .NET 3.5, or whatever) installed. However, Main can't catch these errors because the .exe loads them before main is even executed.

So, my question is, how would I go about creating a launcher that could check for things like .NET 3.5, XNA, etc. and display a nice error message ("This application requires XNA 3.0, download it here!") instead of looking like it crashed?

UPDATE: I should have specified that I want to do this without using an installer. I have a boiler plate WIX installer that allows me to check for dependencies, but sometimes I just want to upload a zip for people to play around with.

like image 985
Jeff Avatar asked Feb 03 '10 22:02

Jeff


3 Answers

To do this without an installer, you might want to create a "launcher" script that does little more than call the "real" entry point after performing any dependency checks up front.

Since missing dependencies appear to be a very common source of pain for you, it's probably advisable to write the launcher in something that goes out of its way to have no dependencies that aren't already on a bare Windows installation, such as an AutoIt script packaged as an executable.

Const $AppTitle = 'Whizzy Game'
Const $MB_ICONERROR = 16

If RegRead('HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\v3.5', 'Install') <> 1 Then
    MsgBox($MB_ICONERROR, $AppTitle, 'The .NET Framework runtime v3.5 is required to run.')
    Exit 1
EndIf

If RegRead('HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\XNA\Framework\v3.1', 'Installed') <> 1 Then
    MsgBox($MB_ICONERROR, $AppTitle, 'The XNA Framework runtime v3.1 is required to run.')
    Exit 1
EndIf

Exit RunWait('WhizzySoftware.WhizzyGame.EntryPoint.exe')
like image 157
Jeffrey Hantin Avatar answered Sep 23 '22 03:09

Jeffrey Hantin


This is done most easily during installation. Include the Microsoft XNA Framework Redistributable with your installation package.

You can use the MsiQueryProductState function to determine if the framework is already installed.

Or you could check the registry for:

[HKEY_LOCAL_MACHINE\Software\Microsoft\XNA\Framework\v3.1]
Installed=1

(This check could alternatively be performed in a launcher application.)

Here's an article about distributing your game with a section on detecting and installing prerequisites.

like image 25
Andy West Avatar answered Sep 23 '22 03:09

Andy West


You could create a setup project (which compiles to an MSI installer) for your application. In the configuration of this installer, you can set prerequisites such as .NET Framework vX.X. I am not absolutely sure about XNA, but I would assume that this can be listed as a prerequisite as well.

like image 30
Jørn Schou-Rode Avatar answered Sep 20 '22 03:09

Jørn Schou-Rode