5

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?

Niels Bosma
  • 11,758
  • 29
  • 89
  • 148
  • You need to read registry settings. Check [this](http://stackoverflow.com/a/199783/649524) excellent answer – Tilak Dec 29 '12 at 18:09
  • I'm not asking what .net versions are installed. I'm asking if full version is installed or not. That post don't answer what exact registry keys I need to check to determine that. – Niels Bosma Dec 29 '12 at 18:14
  • You can check .NET full profile registry setting – Tilak Dec 29 '12 at 18:15
  • .NET switcher -> You will need to maintain different set of projects, solutions, libraries. – Tilak Dec 29 '12 at 18:22
  • Why did you close this question? This is absolutely not the same quesion and does not provide me with the answers I need. – Niels Bosma Dec 29 '12 at 20:50
  • @Tilak: your answer does not help me at all. Why are you closing my questions? – Niels Bosma Dec 29 '12 at 20:52
  • Regarding full version of .NET (which title suggests), sufficient information is there in the marked duplicate. For .NET switcher, either update the title/description, or ask separate question – Tilak Dec 29 '12 at 21:00
  • 2
    My question isn't about what registry keys to look for but an alternative solution. @Tilak: please stay out of this as you're clearly not bringing anything to the table. – Niels Bosma Jan 01 '13 at 13:46

3 Answers3

3

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));
}
Seb Nilsson
  • 26,200
  • 30
  • 103
  • 130
1

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

Community
  • 1
  • 1
Mike Beeler
  • 4,081
  • 2
  • 29
  • 44
  • Yes but what registry keys?. For .net 4.0 is clear, but for .net 3.5? – Niels Bosma Jan 02 '13 at 10:19
  • If you click the link in the above comment see the referenced table. Generally installers handle framework checking issues and I recommend that you use one. They also handle uninstall issues. – Mike Beeler Jan 02 '13 at 11:55
  • @NielsBosma: The client profile version of the framework was first made available with 4.0. You might want to review the following: http://msdn.microsoft.com/en-us/library/bb822049.aspx and http://msdn.microsoft.com/en-us/library/hh925568.aspx as well as the link mike provided. – NotMe Jan 02 '13 at 20:00
0

I would suggest that rather than try and detect which .net version the client computer has, you might just bundle the full .net installer into your installation program.

In other words, detect it at the point of install and take the appropriate actions. This is the usual way of dealing with potentially missing framework parts.

NotMe
  • 87,343
  • 27
  • 171
  • 245