Adding better finding dotnet root location for mac&unix
This commit is contained in:
@@ -192,18 +192,18 @@ namespace Flax.Build
|
||||
case TargetPlatform.Linux:
|
||||
{
|
||||
// TODO: Support /etc/dotnet/install_location
|
||||
|
||||
// Detect custom RID in some distros
|
||||
rid = Utilities.ReadProcessOutput("dotnet", "--info").Split('\n').FirstOrDefault(x => x.StartsWith(" RID:"), "").Replace("RID:", "").Trim();
|
||||
rid = "";
|
||||
ridFallback = $"linux-{arch}";
|
||||
if (rid == ridFallback)
|
||||
ridFallback = "";
|
||||
if (string.IsNullOrEmpty(dotnetPath))
|
||||
dotnetPath ??= SearchForDotnetLocationLinux();
|
||||
|
||||
if (dotnetPath == null)
|
||||
{
|
||||
dotnetPath = "/usr/lib/dotnet/";
|
||||
if (!Directory.Exists(dotnetPath))
|
||||
dotnetPath = "/usr/share/dotnet/";
|
||||
rid = Utilities.ReadProcessOutput("dotnet", "--info").Split('\n').FirstOrDefault(x => x.StartsWith(" RID:"), "").Replace("RID:", "").Trim();
|
||||
if (rid == ridFallback)
|
||||
ridFallback = "";
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case TargetPlatform.Mac:
|
||||
@@ -211,7 +211,12 @@ namespace Flax.Build
|
||||
rid = $"osx-{arch}";
|
||||
ridFallback = "";
|
||||
if (string.IsNullOrEmpty(dotnetPath))
|
||||
dotnetPath = "/usr/local/share/dotnet/";
|
||||
{
|
||||
if (Directory.Exists("/usr/local/share/dotnet")) // Officialy recommended dotnet location
|
||||
dotnetPath = "/usr/local/share/dotnet";
|
||||
else if (Environment.GetEnvironmentVariable("PATH") is string globalBinPath)
|
||||
dotnetPath = globalBinPath.Split(':').FirstOrDefault(x => File.Exists(Path.Combine(x, "dotnet")));
|
||||
}
|
||||
break;
|
||||
}
|
||||
default: throw new InvalidPlatformException(platform);
|
||||
@@ -441,5 +446,18 @@ namespace Flax.Build
|
||||
// TODO: reject 'future' versions like .Net 8?
|
||||
return versions.OrderByDescending(ParseVersion).FirstOrDefault();
|
||||
}
|
||||
|
||||
private static string SearchForDotnetLocationLinux()
|
||||
{
|
||||
if (File.Exists("/etc/dotnet/install_location")) // Officialy recommended dotnet location file
|
||||
return File.ReadAllText("/etc/dotnet/install_location").Trim();
|
||||
if (Directory.Exists("/usr/share/dotnet")) // Officialy recommended dotnet location
|
||||
return"/usr/share/dotnet";
|
||||
if (Directory.Exists("/usr/lib/dotnet")) // Deprecated recommended dotnet location
|
||||
return "/usr/lib/dotnet";
|
||||
if (Environment.GetEnvironmentVariable("PATH") is string globalBinPath) // Searching for dotnet binary
|
||||
return globalBinPath.Split(':').FirstOrDefault(x => File.Exists(Path.Combine(x, "dotnet")));
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user