Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to safely check .NET Framework version using a .NET Framework version that may not exist?

Tags:

c#

.net

I have an application built with .NET 3.5. If a user runs it without having .NET 3.5 installed, I want to have control of what they see and perhaps provide a message that they can understand (with a link to .NET 3.5) versus unhandled exception stack traces. But if they don't actually have .NET 3.5 how can my application control anything?

like image 938
CrashCodes Avatar asked Dec 06 '25 05:12

CrashCodes


1 Answers

Are you assuming that at least SOME version of .NET is installed?

You could write a small loader to be compatible with all versions to do the check.

Or if .NET is not installed, found a simple batch program (though this could easily be done in C++ if you prefer).

@ECHO OFF
SET FileName=%windir%\Microsoft.NET\Framework\v1.1.4322
IF EXIST %FileName% GOTO Skip
ECHO.You currently do not have the Microsoft® .NET Framework 1.1 installed.
ECHO.This is required by the setup program for MyApplication.
ECHO.
ECHO.The Microsoft® .NET Framework 1.1 will now be installed on you system.
ECHO.After completion setup will continue to install MyApplication on your system.
ECHO.
Pause
SET FileName=
Start /WAIT .\dotnetfx.exe
Start .\Setup.exe
ECHO ON
Exit
Tongue Tiedkip
SET FileName=
Start .\Setup.exe
ECHO ON
Exit

This might also help.

like image 148
bdd Avatar answered Dec 07 '25 18:12

bdd



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!