diff --git a/Source/ThirdParty/nethost/nethost.Build.cs b/Source/ThirdParty/nethost/nethost.Build.cs index 6ad833e1e..c8d960db7 100644 --- a/Source/ThirdParty/nethost/nethost.Build.cs +++ b/Source/ThirdParty/nethost/nethost.Build.cs @@ -35,6 +35,8 @@ public class nethost : ThirdPartyModule throw new Exception($"Missing NET SDK {DotNetSdk.MinimumVersion}."); if (!dotnetSdk.GetHostRuntime(options.Platform.Target, options.Architecture, out var hostRuntimePath)) { + if (options.Target.IsPreBuilt) + return; // Ignore missing Host Runtime when engine is already prebuilt if (options.Flags.HasFlag(BuildFlags.GenerateProject)) return; // Ignore missing Host Runtime at projects evaluation stage (not important) throw new Exception($"Missing NET SDK runtime for {options.Platform.Target} {options.Architecture}."); diff --git a/Source/Tools/Flax.Build/Build/DotNet/DotNetSdk.cs b/Source/Tools/Flax.Build/Build/DotNet/DotNetSdk.cs index 5ced97864..342a359e4 100644 --- a/Source/Tools/Flax.Build/Build/DotNet/DotNetSdk.cs +++ b/Source/Tools/Flax.Build/Build/DotNet/DotNetSdk.cs @@ -75,7 +75,7 @@ namespace Flax.Build // Find system-installed SDK string dotnetPath = Environment.GetEnvironmentVariable("DOTNET_ROOT"); string rid, ridFallback, arch; - string[] dotnetSdkVersions = null, dotnetRuntimeVersions = null; + IEnumerable dotnetSdkVersions = null, dotnetRuntimeVersions = null; switch (architecture) { case TargetArchitecture.x86: @@ -147,9 +147,9 @@ namespace Flax.Build return; } if (dotnetSdkVersions == null) - dotnetSdkVersions = Directory.GetDirectories(Path.Combine(dotnetPath, "sdk")).Select(Path.GetFileName).ToArray(); + dotnetSdkVersions = GetVersions(Path.Combine(dotnetPath, "sdk")); if (dotnetRuntimeVersions == null) - dotnetRuntimeVersions = Directory.GetDirectories(Path.Combine(dotnetPath, "shared/Microsoft.NETCore.App/")).Select(Path.GetFileName).ToArray(); + dotnetRuntimeVersions = GetVersions(Path.Combine(dotnetPath, "shared/Microsoft.NETCore.App")); string dotnetSdkVersion = dotnetSdkVersions.OrderByDescending(ParseVersion).FirstOrDefault(); string dotnetRuntimeVersion = dotnetRuntimeVersions.OrderByDescending(ParseVersion).FirstOrDefault(); if (string.IsNullOrEmpty(dotnetSdkVersion)) @@ -235,13 +235,24 @@ namespace Flax.Build { if (string.IsNullOrEmpty(rid)) return false; - var path = Path.Combine(RootPath, $"packs/Microsoft.NETCore.App.Host.{rid}/{RuntimeVersionName}/runtimes/{rid}/native"); - var exists = Directory.Exists(path); + + // Pick pack folder + var packFolder = Path.Combine(RootPath, $"packs/Microsoft.NETCore.App.Host.{rid}"); + var exists = Directory.Exists(packFolder); if (!exists && runtimeName != null) { - path = Path.Combine(RootPath, $"packs/Microsoft.NETCore.App.{runtimeName}.{rid}/{RuntimeVersionName}/runtimes/{rid}/native"); - exists = Directory.Exists(path); + packFolder = Path.Combine(RootPath, $"packs/Microsoft.NETCore.App.{runtimeName}.{rid}"); + exists = Directory.Exists(packFolder); } + if (!exists) + return false; + + // Pick version folder + var versions = GetVersions(packFolder); + var version = GetVersion(versions); + var path = Path.Combine(packFolder, $"{version}/runtimes/{rid}/native"); + exists = Directory.Exists(path); + if (exists) _hostRuntimes[new KeyValuePair(platform, arch)] = path; return exists; @@ -259,5 +270,16 @@ namespace Flax.Build Version ver = new Version(version); return new Version(ver.Major, ver.Minor, ver.Build, rev); } + + private static IEnumerable GetVersions(string folder) + { + return Directory.GetDirectories(folder).Select(Path.GetFileName); + } + + private static string GetVersion(IEnumerable versions) + { + // TODO: reject 'future' versions like .Net 8? + return versions.OrderByDescending(ParseVersion).FirstOrDefault(); + } } }