有没有办法从命令行确定 .NET Framework 版本?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2238696/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Is there a way to determine the .NET Framework version from the command line?
提问by Noah
To troubleshoot an installation, sometimes I just want a quick answer to what version of .NET is installed.
为了对安装进行故障排除,有时我只想快速了解安装的 .NET 版本。
Is there a way to determine the .NET Framework version on a standard Windows system, other than looking at the directories?
除了查看目录之外,有没有办法确定标准 Windows 系统上的 .NET Framework 版本?
NOTE:This is not for a development machine, just out-of-the-box windows
注意:这不适用于开发机器,只是开箱即用的窗口
The following works, but I'm looking for a simpler way.
以下工作,但我正在寻找一种更简单的方法。
dir %WINDIR%\Microsoft.Net\Framework\v*
目录 %WINDIR%\Microsoft.Net\Framework\v*
Directory of C:\Windows\Microsoft.Net\Framework
07/13/2009 07:20 PM <DIR> v1.0.3705
07/13/2009 07:20 PM <DIR> v1.1.4322
01/20/2010 01:16 PM <DIR> v2.0.50727
07/13/2009 09:37 PM <DIR> v3.0
01/20/2010 01:02 PM <DIR> v3.5
02/10/2010 03:20 AM <DIR> v4.0.21006
UPDATE: Not a solution, but another cool directory formatted listing
更新:不是解决方案,而是另一个很酷的目录格式列表
dir %WINDIR%\Microsoft.Net\Framework\v* /O:-N /B
目录 %WINDIR%\Microsoft.Net\Framework\v* /O:-N /B
v4.0.21006
v3.5
v3.0
v2.0.50727
v1.1.4322
v1.0.3705
采纳答案by Josh
Based on your update which indicates this is for walking a non-tech savvy end user through it, I suggest going to Scott Hanselman's site http://www.smallestdotnet.com(use Internet Explorer) which uses the user agent string to tell you which .NET Framework you've got and gives you recommendations for getting up to the latest version in the most efficient manner.
根据您的更新表明这是为了让非技术精明的最终用户通过它,我建议去 Scott Hanselman 的网站http://www.smallestdotnet.com(使用 Internet Explorer),它使用用户代理字符串告诉您您拥有哪个 .NET Framework,并为您提供以最有效的方式升级到最新版本的建议。
Old Answer
With PowerShell you could do this (although the presence of PowerShell already implies at least .NET 2.0)
旧答案
使用 PowerShell,您可以执行此操作(尽管 PowerShell 的存在已经意味着至少 .NET 2.0)
Get-ChildItem "$($Env:WinDir)\Microsoft.Net\Framework" -i mscorlib.dll -r |
ForEach-Object { $_.VersionInfo.ProductVersion }
I don't know if there's a comparable way to get the version information in plain old crusty cmd.exe.
我不知道是否有类似的方法可以在普通的老壳 cmd.exe 中获取版本信息。
回答by Franci Penov
reg query "HKLM\Software\Microsoft\NET Framework Setup\NDP" /s /v version | findstr /i version | sort /+26 /r
The top entry is the latest version of the framework installed.
顶部条目是安装的框架的最新版本。
Note: This doesn't work with v1.x of the framework.
注意:这不适用于框架的 v1.x。
Update: I missed the comment that you are looking for something to tell your dad over the phone. If that's the case, the command above is probably not the best approach for you. You might be better off just telling your dad to open Windows Explorer and navigate him to the .NET Framework dir and telling you the numbers in there.
更新:我错过了您正在寻找通过电话告诉您父亲的评论。如果是这种情况,上面的命令可能不是您的最佳方法。您最好只告诉您父亲打开 Windows 资源管理器并将他导航到 .NET Framework 目录并告诉您那里的数字。
回答by Dave
just open the VS2008 command prompt and type clrver
只需打开 VS2008 命令提示符并键入clrver
回答by t0mm13b
There is an article posted on CodeProjectthat can do just exactly that plus its command line based.
在CodeProject上发布了一篇文章,它可以完全做到这一点,加上它基于命令行。
Hope this helps.
希望这可以帮助。
回答by HotTester
The following would detect if .net framework 3.5 is installed or not.. and if not installed will install it. Just run this on the command prompt.
以下将检测是否安装了 .net framework 3.5.. 如果未安装将安装它。只需在命令提示符下运行它。
if exist "%WINDIR%\Microsoft.Net\Framework\v3.5" goto end start /wait .\Framework\dotnetfx.exe /q /norestart" :end
If you want to detect other versions just replace v3.5 with v2.0 or v1.0 as the case may be. Further if .net is not detected the installation of the .net framework would be done in silent mode i.e. no ui or user interaction.
如果您想检测其他版本,只需根据情况将 v3.5 替换为 v2.0 或 v1.0。此外,如果未检测到 .net,则 .net 框架的安装将在静默模式下完成,即没有 ui 或用户交互。
回答by Dror
EDIT: my answer is irrelevant for the OP question (which was edited after I originally answered).
编辑:我的回答与 OP 问题无关(在我最初回答后进行了编辑)。
According to MSDNyou can use the registry as well to check for installed versions.
根据MSDN,您也可以使用注册表来检查已安装的版本。
In addition thissite claims that there is a command line application called csc you can use - haven't tried it though, I use the registry way during installations I run.
此外,该站点声称有一个名为 csc 的命令行应用程序可供您使用——不过我还没有尝试过,我在运行安装过程中使用了注册表方式。
回答by Joshua
The highest version number from that directory listing is the installed version.
该目录列表中的最高版本号是已安装的版本。
As you can see, any version includes all previous versions, so check for support of a specific version = check for that specific directory.
如您所见,任何版本都包含所有以前的版本,因此检查对特定版本的支持 = 检查该特定目录。

