简体   繁体   English

检测是否从 3.5 上运行的 C# 代码安装了 MSBuild/.net 4?

[英]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.我有一个在 .net 3.5 SP1 上运行的应用程序,它应该检查是否安装了 .net 4。

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");实际上,我更感兴趣的是是否安装了 MSBuild v4,这可以归结为一个简单的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?但是,除了 4.0.30319 版本(和 Windir,但很容易解决)的脆弱性之外,我想知道是否有更合适的方法,例如 API?

I saw this blog post but hope a @JaredPar or similar will be in with something neater!我看到了这篇博文,但希望@JaredPar 或类似的东西会更整洁!

(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)我怀疑对于 .NET 版本,.buildnumber 位保证在 RTM(甚至 SP)之后不会移动

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]请记住,Framework (vs Framework64) 位也不一定稳定 [并且正如引用的博客文章的评论中所指出的那样,您可能需要将 Wow6432Node 考虑在内用于注册表方面]

Are you actually after the path to msbuild.exe or do you need to know if .NET 4 is present?您实际上是在 msbuild.exe 的路径之后还是需要知道 .NET 4 是否存在? Are any predefined symbols in MSBuild useful / does reflectoring into msbuild.exe yield anything?) MSBuild 中的任何预定义符号是否有用/反射到 msbuild.exe 是否会产生任何结果?)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM