このページは、github.comに登録されているDotNetDetectorのREADME.mdを日本語化したものです。英語版は、github.comを参照してください。
NishySoftware.DotNetDetector
開発ステータス
概要
NishySoftware.DotNetDetector / NishySoftware.DotNetDetector.DNF は .NET Framewrokや.NET Coreのバージョンを検出する機能を提供します。
- アプリをビルドしたときのターゲットに設定した .NET Framework / .NET Core のバージョン (NishySoftware.DotNetDetector)
- 起動中のアプリケーションで使われている(ホストしている) .NET Framework / .NET Core のバージョン (NishySoftware.DotNetDetector)
- システムにインストールされている.NET Framework のバージョン (NishySoftware.DotNetDetector.DNF)
インストール
NuGetのパッケージをインストールします。
PM> Install-Package NishySoftware.DotNetDetector
PM> Install-Package NishySoftware.DotNetDetector.DNF
- NishySoftware.DotNetDetector – DotNetDetector ライブラリー
- NishySoftware.DotNetDetector.DNF – DotNetDetector.DNF ライブラリー
機能 / 使用方法
NishySoftware.DotNetDetector
このライブラリーはstatic DotNetDetectorクラスを提供します。すべての公開メソッドは、静的メソッドして公開されています。
DetectAppTargetNetType()
DotNetDetector.FrameworkTypes DetectAppTargetNetType()
このメソッドは、フレームワークの種類を返します。
public enum FrameworkTypes
{
Unknown = 0,
DotNetFramework = 1,
DotNet = 2,
DotNetCore = DotNet,
}
DetectAppTargetNetVersion()
Version DetectAppTargetNetVersion()
このメソッドは、アプリのビルド時にTargetFrameworkとして指定されていた .NET Framework または .NET Coreのバージョンを返します。
判定できなかった場合は、nullを返します。
DetectAppRuntimeNetVersion()
Version DetectAppRuntimeNetVersion()
このメソッドは、実行中のアプリを実行している(ホストしている) .NET Framework または .NET Coreのバージョンを返します。
判定できなかった場合は、nullを返します。
NishySoftware.DotNetDetector.DNF
このライブラリーはstatic DotNetDetectorDNFクラスを提供します。すべての公開メソッドは、静的メソッドして公開されています。
Version DetectInstalledNetFrameworkVersion()
Version DetectInstalledNetFrameworkVersion()
このメソッドは、Windowsシステムにインストールされている.NET Frameworkの最大バージョンの最大値を返します。
判定できなかった場合は、nullを返します。
サンプルコード
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());
}
}
}
.NET Framework 4.7.2 アプリによる実行結果
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
.NET Core 2.2 アプリによる実行結果
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
.NET Core 5.0 アプリによる実行結果 (.NET 5.0.0-rc1 ランタイムを使用時)
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
このライブラリーは the MIT License (MIT)で提供されます。
