views:

160

answers:

1

I have an application that is running on .net 3.5 SP1 and that is supposed to check if .net 4 is installed.

Actually, I'm more interested if MSBuild v4 is installed, which would boil down to a simple File.Exists(@"C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe");

However, apart from the fragility of the 4.0.30319 Version (and the Windir, but that's easy to solve), I wonder if there is a more appropriate way, like an API?

+1  A: 

I saw this blog post but hope a @JaredPar or similar will be in with something neater!

(Still looking for way to derive install dir cleanly

I suspec that for a .NET version, the .buildnumber bit is guaranteed not to move after RTM (or even even SPs)

Remember the Framework (vs Framework64) bit is also not necessarily stable [and as pointed out in the comments to the cited blog article, you may need to take Wow6432Node into account for the registry side of this]

Are you actually after the path to msbuild.exe or do you need to know if .NET 4 is present? Are any predefined symbols in MSBuild useful / does reflectoring into msbuild.exe yield anything?)

Ruben Bartelink
Thanks. The Wow6432Node thing is a bit annoying, but luckily I target 64-bit systems only. Looking at InstallPath in `HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\NET Framework Setup\NDP\v4\Full` seems promising and if that's how they officially support it (seems so from the article), that would work. I specifically need to know if msbuild 4 is present, but as far as I know it comes (only) with .net 4, so checking for one gives me the other.
Michael Stum
Yes. Be careful though - msbuild isnt in the client profile so you need to be checking for the key for the full .NET 4 (you'll see that referenced in stuff you hit from googling ".net 4.0 framework directory"
Ruben Bartelink
Also saw some more stuff about how you detect the one for your ambient platform which obv isnt much use for you. Dont have a FW 4 install here so considering this done and dusted :D (Reflectored 3.5 but no sign of anything that's future proofed in the managed assemblies)
Ruben Bartelink
Re Wow6432Node, you should be able to derive somethign neat and suitable from http://stackoverflow.com/questions/1074411/how-to-open-a-wow64-registry-key-from-a-64-bit-net-application
Ruben Bartelink
Tried it on a few PCs and it seems to work fine.
Michael Stum