Search code examples
.net.net-3.5.net-4.0

Detecting if MSBuild/.net 4 is installed from C# code running on 3.5?


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?


Solution

  • 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?)