0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

ASP.NET Core の実行時にランタイムバージョンを得る方法

Last updated at Posted at 2023-02-06

はじめに

ASP.NET Core がどのランタイムで動いているのか確認したいことがありますよね!?
Environment.Version を使うとランタイムのバージョン番号が得られます。。が、下記の条件付きです。

  • .NET Core 3.x and .NET 5+
    • .NET runtime version number / ex. 6.0.13
  • .NET Framework Versions 4, 4.5, 4.5.1, and 4.5.2
    • 4.0.30319.xxxxx
  • .NET Framework 4.6 and later versions, and .NET Core versions before 3.0
    • 4.0.30319.42000

やってみた

下記の環境下で .NET Core 2.1 と .NET 6 の ASP.NET Core アプリで検証しました。

> dotnet --list-runtimes
Microsoft.AspNetCore.All 2.1.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
~省略~
Microsoft.AspNetCore.All 2.1.30 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.1.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
~省略~
Microsoft.AspNetCore.App 2.1.30 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.1.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
~省略~
Microsoft.AspNetCore.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 5.0.1 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
~省略~
Microsoft.AspNetCore.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 6.0.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 6.0.10 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 6.0.11 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 6.0.13 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 7.0.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]

.NET Core 2.1 アプリの実行結果では 4.0.30319.42000 が得られました。
.NET 6 アプリの実行結果では 6.0.13 が得られました。

おわりに

Environment.Version の存在は知ってたのですが、.NET Core 2.1 環境での実行結果が期待する値ではなかったので忘れてました。.NET 6 環境では問題なく利用できそうです。

0
0
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?