4

I have a requirement in my software, in which I need to know whether the client's system have .Net Framework 4.6 installed or not.

What I have tried is -

var frameworkVersion = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full", false)?.GetValue("Version");

The above is giving me the highest version installed, that is - 4.7. From which I can't decide whether the client system have framework 4.6 installed specifically.

Arpit Gupta
  • 1,209
  • 1
  • 22
  • 39
  • Are you asking because you think you can have, say, 4.6.1 installed but not 4.6? If so, each version is an in-place update so 4.6.1 effectively *contains* 4.6. – Wai Ha Lee Nov 30 '17 at 06:11
  • If you're asking because you want to check for 4.6 but no further versions, just check for [393295 or 393297](https://learn.microsoft.com/en-us/dotnet/framework/migration-guide/how-to-determine-which-versions-are-installed) specifically. – Wai Ha Lee Nov 30 '17 at 06:12
  • @WaiHaLee Are you sure that if one have 4.6.2, then the system will definitely have 4.6 installed? Because, if so, it should solve my issue. – Arpit Gupta Nov 30 '17 at 06:13
  • 1
    I am sure, if that helps. – Wai Ha Lee Nov 30 '17 at 07:12
  • 1
    The user can have only *one* 4.x version installed on his machine. If you see 4.7 then you know that any code that targets a lesser version, like 4.6, is going to work. These kind of version checks are not wise btw, simply let [your program update the machine if necessary](https://stackoverflow.com/a/10033128/17034). – Hans Passant Nov 30 '17 at 09:47

1 Answers1

2

This link should give you what you need. Dot net installed versions explanation

To search for a specific version check the number as an equals. They should be backwards compatible, though, so Microsoft recommends checking with greater than the earliest version number you're compatible with.

If you're not forwards compatible..... You might want to fix that.

Dylan Brams
  • 2,089
  • 1
  • 19
  • 36