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.
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).
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")
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.
http://www.asoft.be/prod_netver.html
Use this "good, lightweight, no-install-required program"
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
.Also, see the Stack Overflow question How to detect what .NET Framework versions and service packs are installed? which also mentions:
Article ID: 318785 - Last Review: November 7, 2008 - Revision: 20.1 How to determine which versions of the .NET Framework are installed and whether service packs have been applied.
Unfortunately, it doesn't appear to work, because the
mscorlib.dll
version in the 2.0 directory has a 2.0 version, and there is nomscorlib.dll
version in either the 3.0 or 3.5 directories even though 3.5 SP1 is installed ... Why would the official Microsoft answer be so misinformed?To determine your server's support for .NET Framework 4.5 and later versions (tested through 4.5.2): If you don't have Registry access on the server, but have app publish rights to that server, create an MVC 5 app with a trivial controller, like this:
Then in your Web.config, walk through the desired .NET Framework versions in the following section, changing the
targetFramework
values as desired:Publish each target to your server, then browse to
<app deploy URL>/Default
. If your server supports the target framework, then the simple string will display from your trivial Controller. If not, you'll receive an error like the following:So in this case, my target server doesn't yet support .NET Framework 4.5.2.
Found answer from here:
Open Command Prompt and copy paste one of the below command lines
or
If you want to find versions prior to .NET 4.5, use code for a console application. Like this:
Otherwise you can find .NET 4.5 or later by querying like this:
Then the console result will tell you which versions are installed and available for use with your deployments. This code come in handy, too because you have them as saved solutions for anytime you want to check it in the future.