我实际的问题是,我曾经遇到过的.NET 4.5全设置两个版本:
- (可能)旧的一个,下载SQL Server数据工具时,它也可
- 大小:
50,349,920
- MD5:
a5e81d1b3905ada0a6e35fd6c6a2e1f4
- (可能)较新的一个早上从这里下载: http://www.microsoft.com/visualstudio/eng/downloads
- 大小:
50,352,408
- MD5:
d02dc8b69a702a47c083278938c4d2f1
该版本两种设置是4.5.50709.17929
。 内饰方面,主要区别是netfx_Full.mzz
文件,但提取与7-ZIP我结束了很多的文件具有相同的版本,即使该文件的内容是不同的内容之后(我已经从检查约20个随机文件约426),所以我真的不能告诉哪一个是新的。
有没有一种方法能够可靠地检测已安装的.NET 4.5运行时的实际版本,所以我只能跑,如果它是真正所需的设置?
更新
我已经检查了所有的426个文件有不同的内容,所有这些都具有两种设置相同的ProductVersion和文件版本。 因此,注册表或文件校验和的下一个步骤。
更新2
在注册表中列出的版本是两种设置相同: 4.5.50709
更新3
.NET 4.5.2现已推出:
这.NET Framework的版本上运行并排侧与.NET Framework 3.5 SP1和早期版本,但执行就地更新.NET Framework 4中,.NET框架4.5和.NET Framework 4.5.1。
MS最近修补.NET 4.5恢复向后兼容.NET 4.0的兼容性在某些情况下(见http://blogs.msdn.com/b/dotnet/archive/2012/10/17/net-framework-4-5-off -to-一个伟大-start.aspx )。
这有可能是MS更新这些变化的设置(以便用户升级到.NET 4.5没有碰到麻烦COMPAT),虽然我不知道为什么他们不会改变对安装的版本号。
另外,还要注意有.NET版本号和所报告的运行时版本号之间的差异System.Environment.Version
。 后者仍然是4.0.30319。*的.NET 4.5中,只有版本号的变化(与.NET 4.5的更新,同时还与每个安全更新)。
下面是在野外观察到的运行时版本的一些例子:
基地4.0
- 4.0.30319.1 = .NET 4.0 RTM
- 4.0.30319.269 = .NET 4.0在Windows XP SP3,7,7 SP1(与MS12-035 GDR安全更新)
- 4.0.30319.276 = .NET 4.0在Windows XP SP3(4.0.3运行时更新)
- 4.0.30319.296 = .NET 4.0在Windows XP SP3,7(与MS12-074 GDR安全更新)
- 4.0.30319.544 = .NET 4.0在Windows XP SP3,7,7 SP1(与MS12-035 LDR安全更新)
- 4.0.30319.1008 = .NET 4.0在Windows XP SP3,7,7 SP1(与MS13-052 GDR安全更新)
- 4.0.30319.1022 = .NET 4.0在Windows XP SP3,7,7 SP1(与MS14-009 GDR安全更新)
- 4.0.30319.1026 = .NET 4.0在Windows XP SP3,7,7 SP1(与MS14-057 GDR安全更新)
- 4.0.30319.2034 = .NET 4.0在Windows XP SP3,7,7 SP1(与MS14-009 LDR安全更新)
4.5
- 4.0.30319.17626 = .NET 4.5 RC
- 4.0.30319.17929 = .NET 4.5 RTM
- 4.0.30319.18010在Windows 8 = .NET 4.5
- 4.0.30319.18052在Windows = .NET 4.5 7 SP1 64位
- 4.0.30319.18063在Windows = .NET 4.5 7 SP1 64位(与MS14-009安全更新)
4.5.1
- 4.0.30319.18408 = .NET在Windows 4.5.1 7 SP1 64位
- 4.0.30319.18444 = .NET 4.5.1在Windows 7 SP1 64位(与MS14-009安全更新)
- 4.0.30319.34014 = .NET 4.5.1在Windows 8.1 64位
4.5.2
- 4.0.30319.34209 = .NET在Windows 4.5.2 7 SP1 64位
- 4.0.30319.34209 = .NET 4.5.2在Windows 8.1 64位
4.6及更高版本
我看不出在我的Windows更新历史上任何.NET更新,所以我想更新v18010得到了作为安装的一部分KB 2756872 。
更新:显然微软更新由于在原来的下载数字签名错误的.NET 4.5的设置。 KB 2770445 。
public class DA {
public static class VersionNetFramework {
public static string Get45or451FromRegistry()
{//https://msdn.microsoft.com/en-us/library/hh925568(v=vs.110).aspx
using (RegistryKey ndpKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32).OpenSubKey("SOFTWARE\\Microsoft\\NET Framework Setup\\NDP\\v4\\Full\\"))
{
int releaseKey = Convert.ToInt32(ndpKey.GetValue("Release"));
if (true)
{
return (@"Version: " + CheckFor45DotVersion(releaseKey));
}
}
}
// Checking the version using >= will enable forward compatibility,
// however you should always compile your code on newer versions of
// the framework to ensure your app works the same.
private static string CheckFor45DotVersion(int releaseKey)
{//https://msdn.microsoft.com/en-us/library/hh925568(v=vs.110).aspx
if (releaseKey >= 394271)
return "4.6.1 installed on all other Windows OS versions or later";
if (releaseKey >= 394254)
return "4.6.1 installed on Windows 10 or later";
if (releaseKey >= 393297)
return "4.6 installed on all other Windows OS versions or later";
if (releaseKey >= 393295)
return "4.6 installed with Windows 10 or later";
if (releaseKey >= 379893)
return "4.5.2 or later";
if (releaseKey >= 378758)
return "4.5.1 installed on Windows 8, Windows 7 SP1, or Windows Vista SP2 or later";
if (releaseKey >= 378675)
return "4.5.1 installed with Windows 8.1 or later";
if (releaseKey >= 378389)
return "4.5 or later";
return "No 4.5 or later version detected";
}
public static string GetVersionFromRegistry()
{//https://msdn.microsoft.com/en-us/library/hh925568(v=vs.110).aspx
string res = @"";
// Opens the registry key for the .NET Framework entry.
using (RegistryKey ndpKey =
RegistryKey.OpenRemoteBaseKey(RegistryHive.LocalMachine, "").
OpenSubKey(@"SOFTWARE\Microsoft\NET Framework Setup\NDP\"))
{
// As an alternative, if you know the computers you will query are running .NET Framework 4.5
// or later, you can use:
// using (RegistryKey ndpKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine,
// RegistryView.Registry32).OpenSubKey(@"SOFTWARE\Microsoft\NET Framework Setup\NDP\"))
foreach (string versionKeyName in ndpKey.GetSubKeyNames())
{
if (versionKeyName.StartsWith("v"))
{
RegistryKey versionKey = ndpKey.OpenSubKey(versionKeyName);
string name = (string)versionKey.GetValue("Version", "");
string sp = versionKey.GetValue("SP", "").ToString();
string install = versionKey.GetValue("Install", "").ToString();
if (install == "") //no install info, must be later.
res += (versionKeyName + " " + name) + Environment.NewLine;
else
{
if (sp != "" && install == "1")
{
res += (versionKeyName + " " + name + " SP" + sp) + Environment.NewLine;
}
}
if (name != "")
{
continue;
}
foreach (string subKeyName in versionKey.GetSubKeyNames())
{
RegistryKey subKey = versionKey.OpenSubKey(subKeyName);
name = (string)subKey.GetValue("Version", "");
if (name != "")
sp = subKey.GetValue("SP", "").ToString();
install = subKey.GetValue("Install", "").ToString();
if (install == "") //no install info, must be later.
res += (versionKeyName + " " + name) + Environment.NewLine;
else
{
if (sp != "" && install == "1")
{
res += (" " + subKeyName + " " + name + " SP" + sp) + Environment.NewLine;
}
else if (install == "1")
{
res += (" " + subKeyName + " " + name) + Environment.NewLine;
}
}
}
}
}
}
return res;
}
public static string GetUpdateHistory()
{//https://msdn.microsoft.com/en-us/library/hh925567(v=vs.110).aspx
string res=@"";
using (RegistryKey baseKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32).OpenSubKey(@"SOFTWARE\Microsoft\Updates"))
{
foreach (string baseKeyName in baseKey.GetSubKeyNames())
{
if (baseKeyName.Contains(".NET Framework") || baseKeyName.StartsWith("KB") || baseKeyName.Contains(".NETFramework"))
{
using (RegistryKey updateKey = baseKey.OpenSubKey(baseKeyName))
{
string name = (string)updateKey.GetValue("PackageName", "");
res += baseKeyName + " " + name + Environment.NewLine;
foreach (string kbKeyName in updateKey.GetSubKeyNames())
{
using (RegistryKey kbKey = updateKey.OpenSubKey(kbKeyName))
{
name = (string)kbKey.GetValue("PackageName", "");
res += (" " + kbKeyName + " " + name) + Environment.NewLine;
if (kbKey.SubKeyCount > 0)
{
foreach (string sbKeyName in kbKey.GetSubKeyNames())
{
using (RegistryKey sbSubKey = kbKey.OpenSubKey(sbKeyName))
{
name = (string)sbSubKey.GetValue("PackageName", "");
if (name == "")
name = (string)sbSubKey.GetValue("Description", "");
res += (" " + sbKeyName + " " + name) + Environment.NewLine;
}
}
}
}
}
}
}
}
}
return res;
}
}
}
如果有人需要System.Environment.Version
针对.NET版本值,安排在一个表(需要执行=Vlookup
用Excel等)
这里是一个plunker我为创建。
进入上面的链接,你将能够复制此表图片:
你可以随时去到Windows / Microsoft.net /框架/ 4.0.30319并期待在system.dll中文件...点击右键属性,并查看到details..should告诉你的版本... system.dll中的4.5.2