我的实际问题是我遇到了两个版本的.NET 4.5完整设置:
50,349,920
a5e81d1b3905ada0a6e35fd6c6a2e1f4
50,352,408
d02dc8b69a702a47c083278938c4d2f1
两种设置的版本均为4.5.50709.17929
。在内部,主要的区别是netfx_Full.mzz
文件,但在用7-zip解压缩内容后,我最终得到了大量具有相同版本的文件,即使文件内容不同(我已经检查了大约20个随机文件)来自大约426的文件,所以我无法确定哪一个更新。
有没有办法可靠地检测已安装的.NET 4.5运行时的实际版本,所以只有在真正需要时才能运行安装程序?
更新
我检查了所有具有不同内容的426个文件,并且所有这些文件在两个设置中都具有相同的ProductVersion和FileVersion。因此,注册表或文件校验和是下一步。
更新2
注册表中列出的版本对于两个设置都是相同的:4.5.50709
更新3
.NET 4.5.2现已推出:
此版本的.NET Framework与.NET Framework 3.5 SP1及更早版本并行运行,但执行.NET Framework 4,.NET Framework 4.5和.NET Framework 4.5的就地更新0.1。
答案 0 :(得分:104)
MS最近修补了.NET 4.5,以便在某些情况下恢复与.NET 4.0的向后兼容性(请参阅http://blogs.msdn.com/b/dotnet/archive/2012/10/17/net-framework-4-5-off-to-a-great-start.aspx)。
MS可能会使用这些更改更新设置(以便升级到.NET 4.5的用户不会遇到compat问题),尽管我不知道为什么他们不会这样做#39 ; t更改设置上的版本号。
另请注意,System.Environment.Version
报告的.NET版本号和运行时版本号之间存在差异。后者仍然是4.0.30319。*对于.NET 4.5,只有版本号更改(使用.NET 4.5更新,以及每次安全更新)。
以下是在野外观察到的运行时版本的一些示例:
Base 4.0
<强> 4.5 强>
<强> 4.5.1 强>
<强> 4.5.2 强>
4.6及更高版本
我的Windows Update历史记录中没有看到任何.NET更新,因此我认为v18010的更新是作为KB 2756872的一部分安装的。
更新:由于原始下载中的数字签名错误,显然Microsoft更新了.NET 4.5设置。 KB 2770445
答案 1 :(得分:2)
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;
}
}
}
答案 2 :(得分:2)
如果有人需要针对.net版本的System.Environment.Version
值,请安排在表格中(需要使用excel等执行=Vlookup
...)
这是我为此创建的plunker。
进入上面的链接,您将能够复制此表格图像:
答案 3 :(得分:1)
您可以随时访问Windows / Microsoft.net / Framework / 4.0.30319并查看system.dll文件...右键单击属性并查看详细信息..应显示版本... system.dll for 4.5.2
答案 4 :(得分:0)
您可以使用 powershell 安装所有版本:
Get-ChildItem 'HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP' -Recurse | Get-ItemProperty -Name Version,Release -EA 0 | where { $_.PSChildName -match '^(?!S)\p{L}'} | select PSChildName, Version, Release | Select -ExpandProperty Version | Sort-Object Version
之前的 powershell 命令将查看注册表项并按版本后代排序打印它们
输出示例:
4.8.03761
3.5.30729.4926
4.0.0.0
4.8.03761
3.0.30729.4926
2.0.50727.4927
3.0.6920.4902
3.0.4506.4926