8

I've asked this question yesterday - it was closed as "exact duplicate" by some people who didn't take the time themselves to read questions / comments carefully! So, another try - maybe it gets the time to receive some working answer before being closed for some pointless reason again.

Microsoft has recently released some "update" for .NET Framework. Unfortunately, I don't know any way to find out which version is installed. Framework-Version stays on 4.0.30319.239.

Thanks for some enlightement ;-)

PS: Setting supportedRuntime in app.config to Version=4.0.2 makes the application tell me at startup that 4.0.2 is not installed (in no time - so there must be some place where the "real" version can be found).

Community
  • 1
  • 1
Sascha
  • 2,193
  • 3
  • 24
  • 38
  • 2
    What's the reason you want to detect it? – Uwe Keim Nov 09 '11 at 12:28
  • @HansPassant : Have you ever experienced that even when coding against 4.0.0.0.0 you get changes in behavior just because 4.0.2 EXISTS!? And why does it matter WHY he wants to know? I really want to know WHY the system knows that "4.0.2" is installed and whats the concept behind this shit by introducing dozens of 4.0 frameworks. – springy76 Nov 09 '11 at 12:35
  • Why are people up voting this when you asked an identical question yesterday, and it was closed as a duplicate? – slugster Nov 09 '11 at 12:36
  • @slugster just look at the edit Oded has done. – springy76 Nov 09 '11 at 12:37
  • @slugster: maybe they didn't get a proper answer yesterday because some especially smart people closed the question as duplicate without further investigation. – Sascha Nov 09 '11 at 12:38
  • possible duplicate of [How to detect what .NET Framework versions and service packs are installed?](http://stackoverflow.com/questions/199080/how-to-detect-what-net-framework-versions-and-service-packs-are-installed) – John Saunders Nov 09 '11 at 16:23
  • @JohnSaunders possible offending comment – springy76 Nov 09 '11 at 16:31
  • That's an automatic comment when a vote to close as duplicate occurs. How is it offending? – John Saunders Nov 09 '11 at 16:33
  • @JohnSaunders Are you kidding? Didn't you notice that the "possible duplicate" matters a totally different topic? Is everybody ignoring my comments to this and the already closed-as-duplicate-question? That's really a fine community of "experts" -- I'll call this the wikipedia admin-power syndrome. – springy76 Nov 09 '11 at 16:48
  • I saw your claim and ignored it. Come up with some facts to show how this is any different from the question I linked as a duplicate. – John Saunders Nov 09 '11 at 16:59
  • @JohnSaunders facts are: 1. I answered the question by 2. not using anything mentioned in the "duplicate" question -- you **won't** find the word "sku" in your "duplicate" at all. – springy76 Nov 09 '11 at 17:06
  • @springy76: how is this not the same question as http://stackoverflow.com/questions/199080/how-to-detect-what-net-framework-versions-and-service-packs-are-installed? – John Saunders Nov 09 '11 at 18:09
  • @JohnSaunders : **where** does your linked question differentiate between 4.0, 4.0.1 or 4.0.2? Try it -- the registry keys given by the answers **don't** contain any info about an existing 4.0.2 installation -- and most likely won't even show anything for the upcoming 4.5; which BTW currently (=CTP) is only based on 4.0.1 – springy76 Nov 09 '11 at 18:35
  • 1
    @springy76: you're right. I confused ".NETFramework" with "NET Framework Setup". I'll ask that my close vote be removed. – John Saunders Nov 09 '11 at 19:10

3 Answers3

13

Have a look at:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework\v4.0.30319\SKUs

If you have installed 4.0.2 then there exist these additional nodes:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework\v4.0.30319\SKUs\.NETFramework,Version=v4.0.1
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework\v4.0.30319\SKUs\.NETFramework,Version=v4.0.1,Profile=Client
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework\v4.0.30319\SKUs\.NETFramework,Version=v4.0.2
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework\v4.0.30319\SKUs\.NETFramework,Version=v4.0.2,Profile=Client
springy76
  • 3,706
  • 2
  • 24
  • 46
  • What value / key should be in it when 4.0.2 is installed? – Sascha Nov 09 '11 at 15:45
  • Okay, on my machine, it's only HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework\v4.0.30319\SKUs\.NETFramework,Version=v4.0 HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework\v4.0.30319\SKUs\.NETFramework,Version=v4.0,Profile=Client – Sascha Nov 09 '11 at 16:34
1

This shouldn't make a difference. You don't target specific build numbers of the framework, you target the release number, which in this case is 4.0. What are you doing where you need to know the exact build number?

WTF - why use buildcounters?!

Why wouldn't you? It details the exact version of the framework. Typically you don't release software with a round "this is version 1.0.0.0" because it can cause havoc with versioning for updates/hotfixes etc.

Simply targeting .NET 4.0 should be sufficient.

Matthew Abbott
  • 60,571
  • 9
  • 104
  • 129
  • 3
    Did you spent any thought at any time that a developer might wish to know why his development machine acts different than any other machine in the company? And that this only happens because he has 4.0.2 installed which is visible nowhere but changes the behavior of programs which explicitely are targetting 4.0.0? – springy76 Nov 09 '11 at 12:40
  • 1
    This question quacks like the classic XY question. Question asks about vexing problem Y to actually attempt to solve X. Which is easy to solve but nobody knows X. The OP's dogged persistence only talking about Y doesn't help him get the answer he needs. And insisting that answerers try to guess at X makes no sense. – Hans Passant Nov 09 '11 at 13:06
  • 1
    @HansPassant it would be nice if you'd spend your efforts more in answering the question than writing useless comments with your personal opinion for which nobody has asked for. – Sascha Nov 10 '11 at 07:24
  • Because 4.0.2 adds some features, particularly around SQL LocalDB. – aef123 May 16 '13 at 17:12
1

Let's give it a try:

If you know a special function/method inside a class that is only present in .NET 4.02 but not in .NET 4.0, I would use reflection to e.g. get a list of all methods of a class or the signature of a specific method.

If there are only internal (methods/properties) changes, you could use ILSpy to search for such changes and then use again reflection to check for the changes.

On the other hand, I'm not sure whether some security constraints might hinder you from doing reflection.

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291