--- lang: ja-jp breaks: true --- # C# 実行時に実行環境を判定する 2021-10-11 > [.NET] 実行時にOS・プラットフォーム等の実行環境による条件分岐をする > https://zenn.dev/shimat/articles/78f855a978c188 > runtime/src/libraries/Common/tests/TestUtilities/System/PlatformDetection.cs > https://github.com/dotnet/runtime/blob/57bfe474518ab5b7cfe6bf7424a79ce3af9d6657/src/libraries/Common/tests/TestUtilities/System/PlatformDetection.cs > runtime/src/libraries/Common/tests/TestUtilities/System/PlatformDetection.Unix.cs > https://github.com/dotnet/runtime/blob/49d88890b7d3971054e7a4026d2a508172b5d222/src/libraries/Common/tests/TestUtilities/System/PlatformDetection.Unix.cs > runtime/src/libraries/Common/tests/TestUtilities/System/PlatformDetection.Windows.cs > https://github.com/dotnet/runtime/blob/57bfe474518ab5b7cfe6bf7424a79ce3af9d6657/src/libraries/Common/tests/TestUtilities/System/PlatformDetection.Windows.cs ```csharp= Console.WriteLine("OSPlatform.Windows :" + RuntimeInformation.IsOSPlatform(OSPlatform.Windows)); Console.WriteLine("OSPlatform.OSX :" + RuntimeInformation.IsOSPlatform(OSPlatform.OSX)); Console.WriteLine("OSPlatform.Linux :" + RuntimeInformation.IsOSPlatform(OSPlatform.Linux)); #if NET Console.WriteLine("OSPlatform.FreeBSD :" + RuntimeInformation.IsOSPlatform(OSPlatform.FreeBSD)); #endif Console.WriteLine("FrameworkDescription :" + RuntimeInformation.FrameworkDescription); Console.WriteLine("OSDescription :" + RuntimeInformation.OSDescription); Console.WriteLine("OSArchitecture :" + RuntimeInformation.OSArchitecture); ``` ###### tags: `C#` `OS` `実行環境` `フレームワーク` `判定`