Adding better finding dotnet root location for mac&unix
This commit is contained in:
@@ -192,18 +192,18 @@ namespace Flax.Build
|
|||||||
case TargetPlatform.Linux:
|
case TargetPlatform.Linux:
|
||||||
{
|
{
|
||||||
// TODO: Support /etc/dotnet/install_location
|
// TODO: Support /etc/dotnet/install_location
|
||||||
|
rid = "";
|
||||||
// Detect custom RID in some distros
|
|
||||||
rid = Utilities.ReadProcessOutput("dotnet", "--info").Split('\n').FirstOrDefault(x => x.StartsWith(" RID:"), "").Replace("RID:", "").Trim();
|
|
||||||
ridFallback = $"linux-{arch}";
|
ridFallback = $"linux-{arch}";
|
||||||
if (rid == ridFallback)
|
|
||||||
ridFallback = "";
|
|
||||||
if (string.IsNullOrEmpty(dotnetPath))
|
if (string.IsNullOrEmpty(dotnetPath))
|
||||||
|
dotnetPath ??= SearchForDotnetLocationLinux();
|
||||||
|
|
||||||
|
if (dotnetPath == null)
|
||||||
{
|
{
|
||||||
dotnetPath = "/usr/lib/dotnet/";
|
rid = Utilities.ReadProcessOutput("dotnet", "--info").Split('\n').FirstOrDefault(x => x.StartsWith(" RID:"), "").Replace("RID:", "").Trim();
|
||||||
if (!Directory.Exists(dotnetPath))
|
if (rid == ridFallback)
|
||||||
dotnetPath = "/usr/share/dotnet/";
|
ridFallback = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case TargetPlatform.Mac:
|
case TargetPlatform.Mac:
|
||||||
@@ -211,7 +211,12 @@ namespace Flax.Build
|
|||||||
rid = $"osx-{arch}";
|
rid = $"osx-{arch}";
|
||||||
ridFallback = "";
|
ridFallback = "";
|
||||||
if (string.IsNullOrEmpty(dotnetPath))
|
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;
|
break;
|
||||||
}
|
}
|
||||||
default: throw new InvalidPlatformException(platform);
|
default: throw new InvalidPlatformException(platform);
|
||||||
@@ -441,5 +446,18 @@ namespace Flax.Build
|
|||||||
// TODO: reject 'future' versions like .Net 8?
|
// TODO: reject 'future' versions like .Net 8?
|
||||||
return versions.OrderByDescending(ParseVersion).FirstOrDefault();
|
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