dotnet-installer/scripts/Microsoft.DotNet.Cli.Build.Framework/CurrentPlatform.cs
Bryan Thornbury 6d8b622451 Add Conditional Target capabilities to the build scripts
Make Attribute properties immutable

PR Feedback, bugfixes

PR Feedback
2016-02-24 16:55:11 -08:00

75 lines
No EOL
1.8 KiB
C#

using System;
using System.Runtime.InteropServices;
using Microsoft.Extensions.PlatformAbstractions;
namespace Microsoft.DotNet.Cli.Build.Framework
{
public static class CurrentPlatform
{
public static BuildPlatform Current
{
get
{
return DetermineCurrentPlatform();
}
}
public static bool IsWindows
{
get
{
return RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
}
}
public static bool IsOSX
{
get
{
return RuntimeInformation.IsOSPlatform(OSPlatform.OSX);
}
}
public static bool IsUbuntu
{
get
{
var osname = PlatformServices.Default.Runtime.OperatingSystem;
return string.Equals(osname, "ubuntu", StringComparison.OrdinalIgnoreCase);
}
}
public static bool IsCentOS
{
get
{
var osname = PlatformServices.Default.Runtime.OperatingSystem;
return string.Equals(osname, "centos", StringComparison.OrdinalIgnoreCase);
}
}
private static BuildPlatform DetermineCurrentPlatform()
{
if (IsWindows)
{
return BuildPlatform.Windows;
}
else if (IsOSX)
{
return BuildPlatform.OSX;
}
else if (IsUbuntu)
{
return BuildPlatform.Ubuntu;
}
else if (IsCentOS)
{
return BuildPlatform.CentOS;
}
else
{
return default(BuildPlatform);
}
}
}
}