I build my C# project with .NET 3.5 SP1 Platform. My code will be compiled and for other .NET platform versions too (but later). I need to get the current .NET Framework version in my code. Console output (information about the installed versions I get from the registry):
Installed .NET Framework versions:
v2.0.50727 2.0.50727.5420 SP2
v3.0 3.0.30729.5420 SP2
v3.5 3.5.30729.5420 SP1
v4.5.1 Client 4.5.50938
v4.5.1 Full 4.5.50938
v4.0 Client 4.0.0.0
***
Current .NET Framework version: 2.0.50727.5477
Press any key for exit...
I understand the .NET 3.0 and 3.5 are based on .NET 2.0, but I need to get an exact version of current platform, instead of base platform version.
- Why did I get (via the
Environment.Version) 2.0.50727.5477 instead of 3.5.30729.5420? - Why does the current version have .5477 instead of .5420 in the last number of the version string?
- How can I get the exact version of the current .NET Framework?
My code is based on this article:
static void Main(string[] args) {
NetFrameworkInfo[] frameworks =
ExtendedEnvironment.GetInstalledNetFameworkVersions();
Console.WriteLine("Installed .NET Framework versions:");
foreach (NetFrameworkInfo item in frameworks) {
Console.WriteLine(item);
}
Console.WriteLine("***");
Version version = Environment.Version;
Console.WriteLine("Current .NET Framework version: {0}", version);
Console.WriteLine("Press any key for exit...");
Console.ReadKey();
}
Environment.Versionreturn the invalid (not the exact) version?