Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if full version of .net is installed?

Tags:

c#

.net

I'm building a ExcelDNA plugin that requires the full version of .Net (4.0 or 3.5) (I'm using some parts of System.Web). Because of this, users that only have the client version are getting errors.

I like to prompt the user with an "get the latest" version popup on startup if only the client version is installed.

Is there any foolproof way to check if the full version is installed? By googling it seems many recommends checking the registry, byt this seems error prone as there are many .Net versions. In such a case what paths do I need to check to build:

bool IsFullDotNetVersion()
{

}

Would it be possible/good idea to check the existence for a feature that's only available in the full version? I.e. Is it possible to check is System.Web is present in the environment? (not included in client version of .Net right?)

As a side question: How can I easy test my application with different .net version installed on my system. Is there any .Net switcher?

like image 946
Niels Bosma Avatar asked Oct 06 '22 12:10

Niels Bosma


2 Answers

Look in the GAC to see if System.Web (or whatever assembly you need) is present.

Here is some code that works on my machine.

private static const string BasePath = @"c:\windows\assembly";

public static bool HasDotNetFullversion()
{
    var gacFolders = new List<string>()
    {
        "GAC", "GAC_32", "GAC_64", "GAC_MSIL",
        "NativeImages_v2.0.50727_32", "NativeImages_v2.0.50727_64"
    };

    var assemblyFolders = from gacFolder in gacFolders
                          let path = Path.Combine(BasePath, gacFolder)
                          where Directory.Exists(path)
                          from directory in Directory.GetDirectories(path)
                          select directory;

    var hasSystemWeb = assemblyFolders.Any(x =>
        x.EndsWith("system.web", StringComparison.InvariantCultureIgnoreCase));
}
like image 110
Seb Nilsson Avatar answered Oct 10 '22 18:10

Seb Nilsson


Possible duplicate. How to detect what .NET Framework versions and service packs are installed? short answer is that you need to read the registry

like image 38
Mike Beeler Avatar answered Oct 10 '22 19:10

Mike Beeler