Click here for Japanese page (日本語ページはこちら)
NishySoftware.DotNetDetector / NishySoftware.DotNetDetector.DNF provide the ability to detect various .NET Framework / .NET Core versions.
- Target .NET Framework / .NET Core version when the application was built (NishySoftware.DotNetDetector)
- .NET Framework / .NET Core version used by the running application. (NishySoftware.DotNetDetector)
- .NET Framework version installed on the system (NishySoftware.DotNetDetector.DNF)
Install NuGet package(s).
PM> Install-Package NishySoftware.DotNetDetector
PM> Install-Package NishySoftware.DotNetDetector.DNF
-
NishySoftware.DotNetDetector - DotNetDetector library.
-
NishySoftware.DotNetDetector.DNF - DotNetDetector.DNF library.
This library provides static DotNetDetector
class.
All public methods are exported as static methods.
DotNetDetector.FrameworkTypes DetectAppTargetNetType()
This method returns the framework type.
public enum FrameworkTypes
{
Unknown = 0,
DotNetFramework = 1,
DotNet = 2,
DotNetCore = DotNet,
}
Version DetectAppTargetNetVersion()
This method returns the version of the .NET Framework / .NET Core that was specified as the TargetFramwork at build time. If it cannot be determined, it returns null.
Version DetectAppRuntimeNetVersion()
This method returns the version of .NET Framework / .NET Core used by the running application. If it cannot be determined, null is returned.
This library provides static DotNetDetectorDNF
class.
All public methods are exported as static methods.
Version DetectInstalledNetFrameworkVersion()
This method returns the maximum version of .NET Framework that installed on the system. If it cannot be determined, null is returned.
namespace NishySoftware.Utilities.DotNetDetector.ConsoleApp
{
using NishySoftware.Utilities;
using System;
class Program
{
static void Main(string[] args)
{
// build
var clrVersionBuildtime = System.Reflection.Assembly.GetEntryAssembly().ImageRuntimeVersion;
Console.WriteLine("ImageRuntimeVersion: " + clrVersionBuildtime);
// runtime
var clrVersionRuntime = System.Runtime.InteropServices.RuntimeEnvironment.GetSystemVersion();
Console.WriteLine("RuntimeEnvironment: " + clrVersionRuntime);
Console.WriteLine("Environment.Version: " + Environment.Version.ToString());
// DotNetDetector
var targetFramework = DotNetDetector.DetectAppTargetNetType();
Console.WriteLine("App target framework type: " + targetFramework.ToString());
var targetVersion = DotNetDetector.DetectAppTargetNetVersion();
Console.WriteLine("App target framework version: " + targetVersion?.ToString());
var runtimeVesion0 = DotNetDetector.DetectAppRuntimeNetVersion();
var runtimeVesion = DotNetDetector.DetectAppRuntimeNetVersion(out var previewName);
Console.WriteLine("App runtime framework version: " + runtimeVesion?.ToString() + (string.IsNullOrEmpty(previewName) ? "" : " Preview (" + previewName + ")"));
var installedDotNetFramework = DotNetDetectorDNF.DetectInstalledNetFrameworkVersion();
Console.WriteLine("Installed .NET framework version: " + installedDotNetFramework?.ToString());
}
}
}
ImageRuntimeVersion: v4.0.30319
RuntimeEnvironment: v4.0.30319
Environment.Version: 4.0.30319.42000
App target framework type: DotNetFramework
App target framework version: 4.7.2
App runtime framework version: 4.8.4220.0
Installed .NET framework version: 4.8
ImageRuntimeVersion: v4.0.30319
RuntimeEnvironment: v4.0.30319
Environment.Version: 4.0.30319.42000
App target framework type: DotNet
App target framework version: 2.2
App runtime framework version: 2.2.8
Installed .NET framework version: 4.8
ImageRuntimeVersion: v4.0.30319
RuntimeEnvironment: v4.0.30319
Environment.Version: 5.0.0
App target framework type: DotNet
App target framework version: 5.0
App runtime framework version: 5.0.0 Preview (rc.1.20451.14)
Installed .NET framework version: 4.8
This library is under the MIT License (MIT).