dotnet-installer/src/Microsoft.DotNet.ProjectModel/RuntimeIdentifier.cs
Sridhar Periyasamy 1db27b7ae3 Enable building dotnet-CLI for centos.
I had to patch up a redhat dnx package which supports NETStandard.Library package. It is currently uploaded to dotnet-cli blob storage. This hack will no longer be required when we move to xplat nuget to do 'dotnet restore'. Apart from this there are three issues that are tracked for centos.
- compile-native not yet supported - https://github.com/dotnet/cli/issues/453
- dnu restore crashes intermittently on centos. I need to investigate this a little bit more and file issues on dnx or coreclr. This will make our CI builds very flaky.
- Dotnet restore does not restore native shims when using “centos.7-x64” - https://github.com/dotnet/corefx/issues/5066
2015-12-18 11:32:20 -08:00

69 lines
2 KiB
C#

// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.IO;
using System.Runtime.InteropServices;
namespace Microsoft.DotNet.ProjectModel
{
public static class RuntimeIdentifier
{
public static string Current { get; } = DetermineRID();
private static string DetermineRID()
{
// TODO: Not this, obviously. Do proper RID detection
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
return "win7-x64";
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
if(IsCentOS())
{
return "centos.7.1-x64";
}
else if(IsUbuntu())
{
return "ubuntu.14.04-x64";
}
else
{
// unknown distro. Lets fail fast
throw new InvalidOperationException("Current linux distro is not supported.");
}
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
return "osx.10.10-x64";
}
throw new InvalidOperationException("Current operating system is not supported.");
}
private static bool IsCentOS()
{
return IsLinuxDistro("centos");
}
private static bool IsUbuntu()
{
return IsLinuxDistro("ubuntu");
}
private static bool IsLinuxDistro(string distro)
{
// HACK - A file which can be found in most linux distros
// Did not test in non-en distros
const string OSIDFILE = "/etc/os-release";
if(!File.Exists(OSIDFILE))
{
return false;
}
return File.ReadAllText(OSIDFILE).ToLower().Contains(distro);
}
}
}