判断生产 Windows Server 上安装了哪些 .NET 版本的万无一失的方法是什么?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/139891/
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
What's the foolproof way to tell which version(s) of .NET are installed on a production Windows Server?
提问by Tom Kidd
This question is not so much programming related as it is deployment related.
这个问题与编程无关,而是与部署有关。
I find myself conversing a lot with the group in my company whose job it is to maintain our production Windows servers and deploy our code on them. For legal and compliance reasons, I do not have direct visibility or any control over the servers so the only way I can tell which version(s) of .NET are installed on any of them is through directions I give to that group.
我发现自己与公司中的团队进行了很多交谈,他们的工作是维护我们的生产 Windows 服务器并在其上部署我们的代码。出于法律和合规性原因,我对服务器没有直接的可见性或任何控制权,因此我可以通过我向该组提供的指示来判断其中任何一个上安装了哪些版本的 .NET。
So far, all of the methods I can think of to tell which version(s) are installed (check for Administrative Tools matching 1.1 or 2.0, check for the entries in the "Add/Remove Programs" list, check for the existence of the directories under c:\Windows\Microsoft.NET) are flawed (I've seen at least one machine with 2.0 but no 2.0 entries under Administrative Tools - and that method tells you nothing about 3.0+, the "Add/Remove Programs" list can get out of sync with reality, and the existence of the directories doesn't necessarily mean anything).
到目前为止,我能想到的所有方法都可以判断安装了哪些版本(检查是否与 1.1 或 2.0 匹配的管理工具,检查“添加/删除程序”列表中的条目,检查是否存在c:\Windows\Microsoft.NET 下的目录有缺陷(我已经看到至少一台机器有 2.0 但在管理工具下没有 2.0 条目 - 该方法告诉你关于 3.0+ 的任何信息,“添加/删除程序”列表可能与现实不同步,目录的存在并不一定意味着什么)。
Given that I generally need to know these things are in place in advance (discovering that "oops, this one doesn't have all the versions and service packs you need" doesn't really work well with short maintenance windows) and I have to do the checking "by proxy" since I can't get on the servers directly, what's the foolproof way to tell which version(s) of .NET are installed on a production Windows Server? Preferably some intrinsic way to do so using what the framework installs since it will be quicker and not need some sort of utility to be loaded and also a method which will definitely fail if the frameworks are not properly installed but still have files in place (i.e., there's a directory and gacutil.exe is inded there but that version of the framework is not really "installed")
鉴于我通常需要提前知道这些东西已经到位(发现“哎呀,这个没有你需要的所有版本和服务包”在维护窗口很短的情况下并不能很好地工作),我必须做“通过代理”检查,因为我无法直接进入服务器,判断生产 Windows 服务器上安装了哪些版本的 .NET 的万无一失的方法是什么?最好是使用框架安装的一些内在方法来做到这一点,因为它会更快并且不需要加载某种实用程序,而且如果框架没有正确安装但仍然有文件(即,那里有一个目录和 gacutil.exe,但该版本的框架并没有真正“安装”)
EDIT:In the absence of a good foolproof intrinsic way to do this built into the Framework(s), does anyone know of a good, lightweight, no-install-required program that can find this out? I can imagine someone could easily write one but if one already exists, that would be even better.
编辑:在框架中没有一个很好的万无一失的内在方法来做到这一点,有没有人知道一个好的,轻量级的,不需要安装的程序可以找到这个?我可以想象有人可以轻松地编写一个,但如果已经存在一个,那就更好了。
采纳答案by Vaibhav
You should open up IE on the server for which you are looking for this info, and go to this site: http://www.hanselman.com/smallestdotnet/
您应该在要查找此信息的服务器上打开 IE,然后访问此站点:http: //www.hanselman.com/smallestdotnet/
That's all it takes.
这就是全部。
The site has a script that looks your browser's "UserAgent" and figures out what version (if any) of the .NET Framework you have (or don't have) installed, and displays it automatically (then calculates the total size if you chose to download the .NET Framework).
该站点有一个脚本,可以查看您浏览器的“UserAgent”并找出您安装(或没有)安装的 .NET Framework 版本(如果有),并自动显示它(如果您选择,然后计算总大小)下载 .NET 框架)。
回答by Ed Guiness
You can programmatically check the registry and a few other things as per this blog entry.
您可以按照此博客条目以编程方式检查注册表和其他一些内容。
The registry key to look at is
要查看的注册表项是
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\...]
回答by K.Dias
回答by Jon Cage
As per CodeTrawler's answer, the solution is to enter the following into an explorer window:
根据CodeTrawler 的回答,解决方案是在资源管理器窗口中输入以下内容:
%systemroot%\Microsoft.NET\Framework
%systemroot%\Microsoft.NET\Framework
Then search for:
然后搜索:
Mscorlib.dll
Mscorlib.dll
...and right-click / go to the version tab for each result.
...并右键单击/转到每个结果的版本选项卡。
回答by bruceatk
The Microsoft way is this:
微软的方式是这样的:
MSDN: How to determine Which .NET Framework Versions Are Installed(which directs you to the following registry key: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\...)
MSDN:如何确定哪些.NET框架版本的安装位置(这将引导您到以下注册表项:HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\...)
If you want foolproof that's another thing. I wouldn't worry about an xcopy of the framework folder. If someone did that I would consider the computer broken.
如果你想要万无一失,那是另一回事。我不会担心框架文件夹的 xcopy。如果有人这样做,我会认为电脑坏了。
The most foolproof way would be to write a small program that uses each version of .NET and the libraries that you care about and run them.
最简单的方法是编写一个小程序,使用每个版本的 .NET 和您关心的库并运行它们。
For a no install method, PowerBasicis an excellent tool. It creates small no runtime required exe's. It could automate the checks described in the MS KB article above.
对于无需安装的方法,PowerBasic是一款出色的工具。它创建了小的不需要运行时的 exe。它可以自动执行上面 MS KB 文章中描述的检查。
回答by thin
http://www.asoft.be/prod_netver.html
http://www.asoft.be/prod_netver.html
Use this "good, lightweight, no-install-required program"
使用这个“好的、轻量级的、无需安装的程序”
回答by Jim Deville
If the machine that you want to check has the .NET SDK installed, you can use a SDK command prompt and run the program CLRVer.exe.
如果您要检查的机器安装了 .NET SDK,您可以使用 SDK 命令提示符并运行该程序CLRVer.exe。
回答by Code Trawler
The official Microsoft answer on how to do this is in KB article 318785.
有关如何执行此操作的官方 Microsoft 答案在知识库文章 318785 中。
回答by Orion Adrian
OneTouch deployment will do all the detection and installation of pre-requisites. It's probably best to go with a pre-made solution than trying to roll your own. Trying to roll your own may lead to problems because whatever thing you key on may change with a hotfix or service pack. Likely Microsoft has some heuristic for determining what version is running.
OneTouch 部署将完成所有先决条件的检测和安装。最好使用预先制定的解决方案,而不是尝试推出自己的解决方案。尝试自行推出可能会导致问题,因为您键入的任何内容都可能随修补程序或服务包而改变。微软可能有一些启发式方法来确定正在运行的版本。
回答by Joe
The official way to detect .NET 3.0 is described here
检测.NET 3.0的官方方法在这里描述
http://msdn.microsoft.com/en-us/library/aa480198.aspx
http://msdn.microsoft.com/en-us/library/aa480198.aspx
Flawed, because it requires the caller to have registry access permissions.
有缺陷,因为它要求调用者具有注册表访问权限。
MSDN also mentions a technique for detecting .NET 3.5 by checking the User Agent string:
MSDN 还提到了一种通过检查用户代理字符串来检测 .NET 3.5 的技术:
http://msdn.microsoft.com/en-us/library/bb909885.aspx
http://msdn.microsoft.com/en-us/library/bb909885.aspx
I think Microsoft should have done a better job than this.
我认为微软应该做得比这更好。

