有办法从命令行确定。net框架版本吗?

时间:2021-09-23 11:43:39

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框架版本吗?

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*

dir %列出% \ 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

dir %列出% \微软。净\ Framework \ v * / O:- n / B

v4.0.21006
v3.5
v3.0
v2.0.50727
v1.1.4322
v1.0.3705

7 个解决方案

#1


9  

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框架的用户代理字符串告诉你,给你建议起床到最新版本以最有效的方式。

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.

我不知道是否有一种类似的方法来获得普通陈旧的crusty cmd.exe的版本信息。

#2


20  

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 dir并告诉你里面的数字。

#3


9  

just open the VS2008 command prompt and type clrver

打开VS2008命令提示符,输入clrver

#4


0  

EDIT: my answer is irrelevant for the OP question (which was edited after I originally answered).

编辑:我的回答与OP问题无关(OP问题是在我最初回答后编辑的)。

According to MSDN you can use the registry as well to check for installed versions.

根据MSDN,您还可以使用注册表检查已安装的版本。

In addition this site 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的命令行应用程序,您可以使用——虽然还没有尝试过,但我在运行安装时使用注册表方式。

#5


0  

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或用户交互。

#6


0  

There is an article posted on CodeProject that can do just exactly that plus its command line based.

有一篇文章发布在CodeProject上,它可以精确地做到这一点再加上它的命令行。

Hope this helps.

希望这个有帮助。

#7


-2  

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.

如您所见,任何版本都包含所有以前的版本,因此请检查是否支持特定版本=检查特定目录。

#1


9  

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框架的用户代理字符串告诉你,给你建议起床到最新版本以最有效的方式。

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.

我不知道是否有一种类似的方法来获得普通陈旧的crusty cmd.exe的版本信息。

#2


20  

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 dir并告诉你里面的数字。

#3


9  

just open the VS2008 command prompt and type clrver

打开VS2008命令提示符,输入clrver

#4


0  

EDIT: my answer is irrelevant for the OP question (which was edited after I originally answered).

编辑:我的回答与OP问题无关(OP问题是在我最初回答后编辑的)。

According to MSDN you can use the registry as well to check for installed versions.

根据MSDN,您还可以使用注册表检查已安装的版本。

In addition this site 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的命令行应用程序,您可以使用——虽然还没有尝试过,但我在运行安装时使用注册表方式。

#5


0  

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或用户交互。

#6


0  

There is an article posted on CodeProject that can do just exactly that plus its command line based.

有一篇文章发布在CodeProject上,它可以精确地做到这一点再加上它的命令行。

Hope this helps.

希望这个有帮助。

#7


-2  

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.

如您所见,任何版本都包含所有以前的版本,因此请检查是否支持特定版本=检查特定目录。