Skip to content

Latest commit

 

History

History
164 lines (129 loc) · 6.91 KB

README.md

File metadata and controls

164 lines (129 loc) · 6.91 KB

Click here for Japanese page (日本語ページはこちら)

NishySoftware.DotNetDetector

Development status

Build Status (develop) Build Status (master)

Downloads NuGet NuGet (pre) Release License

Issues Issues Pull Requests Pull Requests

About

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)

Installation

Install NuGet package(s).

PM> Install-Package NishySoftware.DotNetDetector
PM> Install-Package NishySoftware.DotNetDetector.DNF

Features / How to use

NishySoftware.DotNetDetector

This library provides static DotNetDetector class. All public methods are exported as static methods.

DetectAppTargetNetType()

DotNetDetector.FrameworkTypes DetectAppTargetNetType()

This method returns the framework type.

    public enum FrameworkTypes
    {
        Unknown = 0,
        DotNetFramework = 1,
        DotNet = 2,
        DotNetCore = DotNet,
    }

DetectAppTargetNetVersion()

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.

DetectAppRuntimeNetVersion()

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.

NishySoftware.DotNetDetector.DNF

This library provides static DotNetDetectorDNF class. All public methods are exported as static methods.

Version DetectInstalledNetFrameworkVersion()

Version DetectInstalledNetFrameworkVersion()

This method returns the maximum version of .NET Framework that installed on the system. If it cannot be determined, null is returned.

Example

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());
        }
    }
}

Output by .NET Framework 4.7.2 app

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

Output by .NET Core 2.2 app

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

Output by .NET Core 5.0 app (with .NET 5.0.0-rc1 runtime)

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

License

This library is under the MIT License (MIT).