Checking for .NET dependencies before launching

有些话、适合烂在心里 提交于 2019-12-06 03:01:13

问题


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.


回答1:


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')



回答2:


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.




回答3:


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.



来源:https://stackoverflow.com/questions/2196046/checking-for-net-dependencies-before-launching

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!