feat: Adds Build Tool for Publishing/Setup (#2392)
## Summary Replaces the basic `publish.cmd`/`publish.sh` scripts with an interactive **BuildTool** — a C# console app using [Spectre.Console](https://spectreconsole.net/) that guides users through publishing, prerequisite checking, and cross-compilation. ### Why The community found the existing publish scripts unhelpful for newcomers. They worked but didn't walk users through the process, didn't check prerequisites, and provided no feedback when things went wrong. ### What's New **Interactive BuildTool** (`Projects/BuildTool/`) - NativeAOT-compiled C# console app with true-color ASCII logo and ModernUO brand gold/silver palette - Guided publish wizard with step-by-step back navigation (Ctrl+C or menu "Back" to go to previous step) - Prerequisite checking: .NET SDK version, VC++ Redistributable (Windows), native libraries (Linux/macOS) - .NET SDK auto-install offer via Microsoft's official install scripts - Platform detection: Windows 10 vs 11 (build number), macOS codenames, Linux distro + kernel version - Cross-compilation support: skips native library checks, shows target prerequisites after build - Non-interactive mode for CI: `--config Release --skip-prereqs` - Backward-compatible positional args: `publish.cmd release win x64` still works **Shell Wrappers** (`publish.cmd`, `publish.ps1`, `publish.sh`) - Try native BuildTool binary first (downloaded from GitHub Releases) - Fall back to `dotnet run --project Projects/BuildTool` if unavailable - SDK bootstrapping: offer to install .NET if not found **CI/CD Updates** - Build/test workflows target `Projects/Application/Application.csproj` instead of the solution (excludes BuildTool and test projects from publish) - New `build-tool-release.yml` workflow builds NativeAOT binaries for win-x64, win-arm64, osx-arm64, linux-x64, linux-arm64 - Minimum SDK bumped to 10.0.201 (required for Serialization Generator 2.14.3 / Roslyn 5.3.0) **Other Changes** - Solution converted from `.sln` to `.slnx` - Updated README with interactive mode instructions and deployment guidance ## Screenshots <img width="320" height="378" alt="image" src="https://github.com/user-attachments/assets/83c057c5-3992-4dbd-99fa-0e3c24ef6428" /> <img width="749" height="554" alt="image" src="https://github.com/user-attachments/assets/e4ee4d6f-71d4-47f9-86b6-8fd1ca3c3e7a" />
This commit is contained in:
parent
3b4e1137f6
commit
ec4d6a7a85
32 changed files with 2372 additions and 165 deletions
190
Projects/BuildTool/Prerequisites/DotNetSdkManager.cs
Normal file
190
Projects/BuildTool/Prerequisites/DotNetSdkManager.cs
Normal file
|
|
@ -0,0 +1,190 @@
|
|||
using System.Text.Json;
|
||||
using System.Text.RegularExpressions;
|
||||
using BuildTool.Json;
|
||||
using BuildTool.Platform;
|
||||
using BuildTool.Publishing;
|
||||
using Spectre.Console;
|
||||
|
||||
namespace BuildTool.Prerequisites;
|
||||
|
||||
public static partial class DotNetSdkManager
|
||||
{
|
||||
private const string DotNetDownloadUrl = "https://dotnet.microsoft.com/download";
|
||||
private const string InstallScriptUrlWindows = "https://dot.net/v1/dotnet-install.ps1";
|
||||
private const string InstallScriptUrlUnix = "https://dot.net/v1/dotnet-install.sh";
|
||||
|
||||
public static PrerequisiteResult CheckSdk(string repoRoot)
|
||||
{
|
||||
var requiredVersionStr = ReadRequiredVersion(repoRoot) ?? "10.0.201";
|
||||
|
||||
if (!Version.TryParse(requiredVersionStr, out var requiredVersion))
|
||||
{
|
||||
requiredVersion = new Version(10, 0, 201);
|
||||
}
|
||||
|
||||
// Check if dotnet is on PATH
|
||||
var result = ProcessRunner.RunCaptured("dotnet", "--list-sdks");
|
||||
if (!result.Success)
|
||||
{
|
||||
return new PrerequisiteResult
|
||||
{
|
||||
Name = ".NET SDK",
|
||||
Passed = false,
|
||||
Details = $".NET SDK {requiredVersionStr}+ is not installed",
|
||||
DownloadUrl = DotNetDownloadUrl
|
||||
};
|
||||
}
|
||||
|
||||
// Parse installed SDK versions — find the best match
|
||||
Version? bestVersion = null;
|
||||
string? bestVersionStr = null;
|
||||
|
||||
foreach (var line in result.StandardOutput.Split('\n', StringSplitOptions.RemoveEmptyEntries))
|
||||
{
|
||||
var match = SdkVersionRegex().Match(line);
|
||||
if (!match.Success)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var versionStr = match.Groups[1].Value;
|
||||
if (!Version.TryParse(versionStr, out var version))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (bestVersion is null || version > bestVersion)
|
||||
{
|
||||
bestVersion = version;
|
||||
bestVersionStr = versionStr;
|
||||
}
|
||||
}
|
||||
|
||||
if (bestVersion is null || bestVersion < requiredVersion)
|
||||
{
|
||||
return new PrerequisiteResult
|
||||
{
|
||||
Name = ".NET SDK",
|
||||
Passed = false,
|
||||
Details = bestVersionStr is not null
|
||||
? $".NET SDK {bestVersionStr} found, but {requiredVersionStr}+ is required"
|
||||
: $".NET SDK {requiredVersionStr}+ is required but no SDK was found",
|
||||
DownloadUrl = DotNetDownloadUrl
|
||||
};
|
||||
}
|
||||
|
||||
return new PrerequisiteResult
|
||||
{
|
||||
Name = ".NET SDK",
|
||||
Passed = true,
|
||||
Details = $".NET SDK {bestVersionStr}"
|
||||
};
|
||||
}
|
||||
|
||||
public static bool OfferInstall(PlatformInfo platform, bool interactive)
|
||||
{
|
||||
if (!interactive)
|
||||
{
|
||||
AnsiConsole.MarkupLine("[red]Error:[/] .NET SDK is not installed. Download from:");
|
||||
AnsiConsole.MarkupLine($"[link]{DotNetDownloadUrl}[/]");
|
||||
return false;
|
||||
}
|
||||
|
||||
var install = AnsiConsole.Confirm(
|
||||
"[yellow].NET SDK is required but not found.[/] Would you like to install it now?",
|
||||
defaultValue: true
|
||||
);
|
||||
|
||||
if (!install)
|
||||
{
|
||||
AnsiConsole.MarkupLine($"\nDownload the .NET SDK from: [link]{DotNetDownloadUrl}[/]");
|
||||
return false;
|
||||
}
|
||||
|
||||
return RunInstallScript(platform);
|
||||
}
|
||||
|
||||
private static bool RunInstallScript(PlatformInfo platform)
|
||||
{
|
||||
AnsiConsole.MarkupLine("\n[blue]Installing .NET SDK...[/]");
|
||||
|
||||
if (platform.IsWindows)
|
||||
{
|
||||
return RunWindowsInstall();
|
||||
}
|
||||
|
||||
return RunUnixInstall();
|
||||
}
|
||||
|
||||
private static bool RunWindowsInstall()
|
||||
{
|
||||
// Download and run the official Microsoft install script
|
||||
var result = ProcessRunner.RunPassthrough(
|
||||
"powershell",
|
||||
$"-NoProfile -ExecutionPolicy Bypass -Command \"& {{ " +
|
||||
$"[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; " +
|
||||
$"$script = Invoke-WebRequest -Uri '{InstallScriptUrlWindows}' -UseBasicParsing; " +
|
||||
$"$scriptBlock = [scriptblock]::Create($script.Content); " +
|
||||
$"& $scriptBlock -Channel 10.0 }}\""
|
||||
);
|
||||
|
||||
if (result != 0)
|
||||
{
|
||||
AnsiConsole.MarkupLine("[red]Failed to install .NET SDK.[/]");
|
||||
AnsiConsole.MarkupLine($"Please install manually from: [link]{DotNetDownloadUrl}[/]");
|
||||
return false;
|
||||
}
|
||||
|
||||
AnsiConsole.MarkupLine("[green]Successfully installed .NET SDK.[/]");
|
||||
AnsiConsole.MarkupLine("[yellow]Note:[/] You may need to restart your terminal for the PATH to update.");
|
||||
return true;
|
||||
}
|
||||
|
||||
private static bool RunUnixInstall()
|
||||
{
|
||||
// Download and run the official Microsoft install script
|
||||
var result = ProcessRunner.RunPassthrough(
|
||||
"bash",
|
||||
$"-c \"curl -fsSL {InstallScriptUrlUnix} | bash -s -- --channel 10.0\""
|
||||
);
|
||||
|
||||
if (result != 0)
|
||||
{
|
||||
AnsiConsole.MarkupLine("[red]Failed to install .NET SDK.[/]");
|
||||
AnsiConsole.MarkupLine($"Please install manually from: [link]{DotNetDownloadUrl}[/]");
|
||||
return false;
|
||||
}
|
||||
|
||||
AnsiConsole.MarkupLine("[green]Successfully installed .NET SDK.[/]");
|
||||
AnsiConsole.MarkupLine("[yellow]Note:[/] You may need to add ~/.dotnet to your PATH or restart your terminal.");
|
||||
return true;
|
||||
}
|
||||
|
||||
private static string? ReadRequiredVersion(string repoRoot)
|
||||
{
|
||||
var globalJsonPath = Path.Combine(repoRoot, "global.json");
|
||||
if (!File.Exists(globalJsonPath))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var json = File.ReadAllText(globalJsonPath);
|
||||
var globalJson = JsonSerializer.Deserialize(json, GlobalJsonContext.Default.GlobalJson);
|
||||
return globalJson?.Sdk?.Version;
|
||||
}
|
||||
|
||||
// Kept for reference but no longer used — Version.TryParse handles comparison now
|
||||
private static int ParseMajorVersion(string version)
|
||||
{
|
||||
var dotIndex = version.IndexOf('.');
|
||||
if (dotIndex <= 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return int.TryParse(version.AsSpan(0, dotIndex), out var major) ? major : 0;
|
||||
}
|
||||
|
||||
[GeneratedRegex(@"^(\d+\.\d+\.\d+\S*)")]
|
||||
private static partial Regex SdkVersionRegex();
|
||||
}
|
||||
309
Projects/BuildTool/Prerequisites/NativeLibraryChecker.cs
Normal file
309
Projects/BuildTool/Prerequisites/NativeLibraryChecker.cs
Normal file
|
|
@ -0,0 +1,309 @@
|
|||
using BuildTool.Platform;
|
||||
using BuildTool.Publishing;
|
||||
|
||||
namespace BuildTool.Prerequisites;
|
||||
|
||||
public static class NativeLibraryChecker
|
||||
{
|
||||
/// <summary>
|
||||
/// Returns the required prerequisites for a target OS (without checking the local machine).
|
||||
/// Used to inform users what they need to install on the deployment target after cross-compiling.
|
||||
/// </summary>
|
||||
public static (string Description, string[] InstallCommands) GetRequirementsForTarget(string targetOs)
|
||||
{
|
||||
return targetOs switch
|
||||
{
|
||||
"win" => (
|
||||
"Windows",
|
||||
[
|
||||
".NET 10 Runtime — https://dotnet.microsoft.com/download/dotnet/10.0",
|
||||
"VC++ Redistributable v14 — https://aka.ms/vs/17/release/vc_redist.x64.exe"
|
||||
]
|
||||
),
|
||||
"osx" => (
|
||||
"macOS",
|
||||
[
|
||||
".NET 10 Runtime — https://dotnet.microsoft.com/download/dotnet/10.0",
|
||||
"brew install icu4c libdeflate zstd argon2"
|
||||
]
|
||||
),
|
||||
"linux" => (
|
||||
"Linux",
|
||||
[
|
||||
".NET 10 Runtime — https://dotnet.microsoft.com/download/dotnet/10.0",
|
||||
"Debian/Ubuntu: sudo apt-get install -y libicu-dev libdeflate-dev zstd libargon2-dev liburing-dev",
|
||||
"Fedora/RHEL: sudo dnf install -y libicu libdeflate-devel zstd libargon2-devel liburing-devel",
|
||||
"CentOS: Also requires epel-release and CRB enabled"
|
||||
]
|
||||
),
|
||||
_ => ("Unknown", [".NET 10 Runtime — https://dotnet.microsoft.com/download/dotnet/10.0"])
|
||||
};
|
||||
}
|
||||
|
||||
public static List<PrerequisiteResult> Check(PlatformInfo platform)
|
||||
{
|
||||
if (platform.IsWindows)
|
||||
{
|
||||
return CheckWindows(platform);
|
||||
}
|
||||
|
||||
if (platform.IsMacOS)
|
||||
{
|
||||
return CheckMacOS();
|
||||
}
|
||||
|
||||
if (platform.IsLinux)
|
||||
{
|
||||
return CheckLinux(platform);
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
private static List<PrerequisiteResult> CheckWindows(PlatformInfo platform)
|
||||
{
|
||||
var results = new List<PrerequisiteResult>();
|
||||
|
||||
// Check VC++ Redistributable via registry
|
||||
var vcRedistInstalled = CheckVcRedist(platform.ArchRid);
|
||||
var downloadUrl = platform.ArchRid == "arm64"
|
||||
? "https://aka.ms/vs/17/release/vc_redist.arm64.exe"
|
||||
: "https://aka.ms/vs/17/release/vc_redist.x64.exe";
|
||||
|
||||
results.Add(new PrerequisiteResult
|
||||
{
|
||||
Name = "VC++ Redistributable v14",
|
||||
Passed = vcRedistInstalled,
|
||||
Details = vcRedistInstalled ? "Installed" : "Not found",
|
||||
DownloadUrl = vcRedistInstalled ? null : downloadUrl
|
||||
});
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
private static bool CheckVcRedist(string arch)
|
||||
{
|
||||
if (!OperatingSystem.IsWindows())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check multiple known registry paths for VC++ 14.x Redistributable
|
||||
string[] registryPaths =
|
||||
[
|
||||
$@"SOFTWARE\Microsoft\VisualStudio\14.0\VC\Runtimes\{arch}",
|
||||
$@"SOFTWARE\WOW6432Node\Microsoft\VisualStudio\14.0\VC\Runtimes\{arch}"
|
||||
];
|
||||
|
||||
foreach (var path in registryPaths)
|
||||
{
|
||||
try
|
||||
{
|
||||
using var key = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(path);
|
||||
if (key?.GetValue("Installed") is int installed && installed == 1)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Registry access may fail, continue checking
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private static List<PrerequisiteResult> CheckMacOS()
|
||||
{
|
||||
var results = new List<PrerequisiteResult>();
|
||||
|
||||
// Check if Homebrew is installed
|
||||
var brewResult = ProcessRunner.RunCaptured("which", "brew");
|
||||
if (!brewResult.Success)
|
||||
{
|
||||
results.Add(new PrerequisiteResult
|
||||
{
|
||||
Name = "Homebrew",
|
||||
Passed = false,
|
||||
Details = "Homebrew is required to install native dependencies",
|
||||
DownloadUrl = "https://brew.sh"
|
||||
});
|
||||
return results;
|
||||
}
|
||||
|
||||
// Check required Homebrew formulae
|
||||
var formulae = new[] { "icu4c", "libdeflate", "zstd", "argon2" };
|
||||
var listResult = ProcessRunner.RunCaptured("brew", "list --formula");
|
||||
var installedFormulae = listResult.Success
|
||||
? new HashSet<string>(
|
||||
listResult.StandardOutput.Split('\n', StringSplitOptions.RemoveEmptyEntries),
|
||||
StringComparer.OrdinalIgnoreCase)
|
||||
: new HashSet<string>(StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
var missing = new List<string>();
|
||||
foreach (var formula in formulae)
|
||||
{
|
||||
var installed = installedFormulae.Contains(formula);
|
||||
if (!installed)
|
||||
{
|
||||
missing.Add(formula);
|
||||
}
|
||||
|
||||
results.Add(new PrerequisiteResult
|
||||
{
|
||||
Name = formula,
|
||||
Passed = installed,
|
||||
Details = installed ? "Installed" : "Not installed",
|
||||
InstallCommand = installed ? null : $"brew install {formula}"
|
||||
});
|
||||
}
|
||||
|
||||
if (missing.Count > 0)
|
||||
{
|
||||
results.Add(new PrerequisiteResult
|
||||
{
|
||||
Name = "Install all missing",
|
||||
Passed = false,
|
||||
IsWarning = true,
|
||||
Details = "Run the following command to install all missing dependencies:",
|
||||
InstallCommand = $"brew install {string.Join(' ', missing)}"
|
||||
});
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
private static List<PrerequisiteResult> CheckLinux(PlatformInfo platform)
|
||||
{
|
||||
return platform.PackageManager switch
|
||||
{
|
||||
PackageManager.Apt => CheckLinuxApt(),
|
||||
PackageManager.Dnf => CheckLinuxDnf(platform),
|
||||
_ => CheckLinuxGeneric(platform)
|
||||
};
|
||||
}
|
||||
|
||||
private static List<PrerequisiteResult> CheckLinuxApt()
|
||||
{
|
||||
var results = new List<PrerequisiteResult>();
|
||||
var packages = new[] { "libicu-dev", "libdeflate-dev", "zstd", "libargon2-dev", "liburing-dev" };
|
||||
var missing = new List<string>();
|
||||
|
||||
foreach (var package in packages)
|
||||
{
|
||||
var result = ProcessRunner.RunCaptured("dpkg", $"-l {package}");
|
||||
var installed = result.Success && result.StandardOutput.Contains("ii");
|
||||
|
||||
if (!installed)
|
||||
{
|
||||
missing.Add(package);
|
||||
}
|
||||
|
||||
results.Add(new PrerequisiteResult
|
||||
{
|
||||
Name = package,
|
||||
Passed = installed,
|
||||
Details = installed ? "Installed" : "Not installed"
|
||||
});
|
||||
}
|
||||
|
||||
if (missing.Count > 0)
|
||||
{
|
||||
results.Add(new PrerequisiteResult
|
||||
{
|
||||
Name = "Install all missing",
|
||||
Passed = false,
|
||||
IsWarning = true,
|
||||
Details = "Run the following command to install all missing dependencies:",
|
||||
InstallCommand = $"sudo apt-get install -y {string.Join(' ', missing)}"
|
||||
});
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
private static List<PrerequisiteResult> CheckLinuxDnf(PlatformInfo platform)
|
||||
{
|
||||
var results = new List<PrerequisiteResult>();
|
||||
var packages = new[] { "libicu", "libdeflate-devel", "zstd", "libargon2-devel", "liburing-devel" };
|
||||
var missing = new List<string>();
|
||||
|
||||
foreach (var package in packages)
|
||||
{
|
||||
var result = ProcessRunner.RunCaptured("rpm", $"-q {package}");
|
||||
var installed = result.Success;
|
||||
|
||||
if (!installed)
|
||||
{
|
||||
missing.Add(package);
|
||||
}
|
||||
|
||||
results.Add(new PrerequisiteResult
|
||||
{
|
||||
Name = package,
|
||||
Passed = installed,
|
||||
Details = installed ? "Installed" : "Not installed"
|
||||
});
|
||||
}
|
||||
|
||||
// Check if this is CentOS (needs EPEL)
|
||||
var isCentOs = platform.DistroId?.Equals("centos", StringComparison.OrdinalIgnoreCase) == true;
|
||||
if (isCentOs && missing.Count > 0)
|
||||
{
|
||||
results.Add(new PrerequisiteResult
|
||||
{
|
||||
Name = "EPEL Repository",
|
||||
Passed = false,
|
||||
IsWarning = true,
|
||||
Details = "CentOS requires EPEL for some packages. Enable it first:",
|
||||
InstallCommand = "sudo dnf install -y epel-release epel-next-release && sudo dnf config-manager --set-enabled crb"
|
||||
});
|
||||
}
|
||||
|
||||
if (missing.Count > 0)
|
||||
{
|
||||
results.Add(new PrerequisiteResult
|
||||
{
|
||||
Name = "Install all missing",
|
||||
Passed = false,
|
||||
IsWarning = true,
|
||||
Details = "Run the following command to install all missing dependencies:",
|
||||
InstallCommand = $"sudo dnf install -y {string.Join(' ', missing)}"
|
||||
});
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
private static List<PrerequisiteResult> CheckLinuxGeneric(PlatformInfo platform)
|
||||
{
|
||||
var results = new List<PrerequisiteResult>();
|
||||
|
||||
// Use ldconfig to check for shared libraries
|
||||
var ldResult = ProcessRunner.RunCaptured("ldconfig", "-p");
|
||||
var ldOutput = ldResult.Success ? ldResult.StandardOutput : "";
|
||||
|
||||
var libraries = new Dictionary<string, string>
|
||||
{
|
||||
["libicu"] = "libicuuc",
|
||||
["libdeflate"] = "libdeflate",
|
||||
["zstd"] = "libzstd",
|
||||
["libargon2"] = "libargon2",
|
||||
["liburing"] = "liburing"
|
||||
};
|
||||
|
||||
foreach (var (name, soName) in libraries)
|
||||
{
|
||||
var found = ldOutput.Contains(soName, StringComparison.OrdinalIgnoreCase);
|
||||
results.Add(new PrerequisiteResult
|
||||
{
|
||||
Name = name,
|
||||
Passed = found,
|
||||
Details = found ? "Found" : "Not found — install using your package manager"
|
||||
});
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
}
|
||||
165
Projects/BuildTool/Prerequisites/PrerequisiteChecker.cs
Normal file
165
Projects/BuildTool/Prerequisites/PrerequisiteChecker.cs
Normal file
|
|
@ -0,0 +1,165 @@
|
|||
using BuildTool.Platform;
|
||||
using Spectre.Console;
|
||||
|
||||
namespace BuildTool.Prerequisites;
|
||||
|
||||
public static class PrerequisiteChecker
|
||||
{
|
||||
/// <summary>
|
||||
/// Runs all prerequisite checks (SDK + native libraries) and displays results.
|
||||
/// Returns true if all critical prerequisites pass.
|
||||
/// </summary>
|
||||
public static bool CheckAll(PlatformInfo platform, string repoRoot, bool interactive)
|
||||
{
|
||||
var panel = new Panel("[bold]Checking prerequisites[/]")
|
||||
.Border(BoxBorder.Rounded)
|
||||
.BorderColor(Branding.Gold)
|
||||
.Padding(1, 0);
|
||||
AnsiConsole.Write(panel);
|
||||
AnsiConsole.WriteLine();
|
||||
|
||||
if (!CheckSdkInternal(platform, repoRoot, interactive))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return CheckNativeLibrariesInternal(platform, interactive);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks only the .NET SDK (sufficient for cross-compilation).
|
||||
/// Returns true if the SDK is available.
|
||||
/// </summary>
|
||||
public static bool CheckSdk(PlatformInfo platform, string repoRoot, bool interactive)
|
||||
{
|
||||
var panel = new Panel("[bold]Checking .NET SDK[/]")
|
||||
.Border(BoxBorder.Rounded)
|
||||
.BorderColor(Branding.Gold)
|
||||
.Padding(1, 0);
|
||||
AnsiConsole.Write(panel);
|
||||
AnsiConsole.WriteLine();
|
||||
|
||||
var passed = CheckSdkInternal(platform, repoRoot, interactive);
|
||||
AnsiConsole.WriteLine();
|
||||
return passed;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks native libraries for the current platform.
|
||||
/// Call this only when the publish target matches the current OS.
|
||||
/// Returns true if all pass or the user chose to continue.
|
||||
/// </summary>
|
||||
public static bool CheckNativeLibraries(PlatformInfo platform, bool interactive)
|
||||
{
|
||||
AnsiConsole.Write(new Panel("[bold]Checking native libraries[/]")
|
||||
.Border(BoxBorder.Rounded)
|
||||
.BorderColor(Branding.Gold)
|
||||
.Padding(1, 0));
|
||||
AnsiConsole.WriteLine();
|
||||
|
||||
var passed = CheckNativeLibrariesInternal(platform, interactive);
|
||||
AnsiConsole.WriteLine();
|
||||
return passed;
|
||||
}
|
||||
|
||||
private static bool CheckSdkInternal(PlatformInfo platform, string repoRoot, bool interactive)
|
||||
{
|
||||
var sdkResult = DotNetSdkManager.CheckSdk(repoRoot);
|
||||
DisplayResult(sdkResult);
|
||||
|
||||
if (!sdkResult.Passed)
|
||||
{
|
||||
var installed = DotNetSdkManager.OfferInstall(platform, interactive);
|
||||
if (!installed)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
sdkResult = DotNetSdkManager.CheckSdk(repoRoot);
|
||||
if (!sdkResult.Passed)
|
||||
{
|
||||
AnsiConsole.MarkupLine("[red]SDK installation may require a terminal restart.[/]");
|
||||
return false;
|
||||
}
|
||||
|
||||
DisplayResult(sdkResult);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private static bool CheckNativeLibrariesInternal(PlatformInfo platform, bool interactive)
|
||||
{
|
||||
var nativeResults = NativeLibraryChecker.Check(platform);
|
||||
var hasMissing = false;
|
||||
|
||||
foreach (var result in nativeResults)
|
||||
{
|
||||
if (result.IsWarning)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
DisplayResult(result);
|
||||
if (!result.Passed)
|
||||
{
|
||||
hasMissing = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (hasMissing)
|
||||
{
|
||||
AnsiConsole.WriteLine();
|
||||
|
||||
foreach (var result in nativeResults)
|
||||
{
|
||||
if (!result.IsWarning)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (result.InstallCommand is not null)
|
||||
{
|
||||
AnsiConsole.MarkupLine($" [yellow]:warning: {result.Details}[/]");
|
||||
AnsiConsole.MarkupLine($" [white on grey23] {result.InstallCommand} [/]");
|
||||
AnsiConsole.WriteLine();
|
||||
}
|
||||
}
|
||||
|
||||
if (interactive)
|
||||
{
|
||||
var continueAnyway = AnsiConsole.Confirm(
|
||||
"[yellow]Some prerequisites are missing. Continue anyway?[/]",
|
||||
defaultValue: false
|
||||
);
|
||||
|
||||
if (!continueAnyway)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return interactive; // In interactive mode, user chose to continue
|
||||
}
|
||||
|
||||
AnsiConsole.MarkupLine("[green]:check_mark_button: All prerequisites satisfied.[/]");
|
||||
return true;
|
||||
}
|
||||
|
||||
private static void DisplayResult(PrerequisiteResult result)
|
||||
{
|
||||
if (result.IsWarning)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var icon = result.Passed ? "[green]:check_mark:[/]" : "[red]:cross_mark:[/]";
|
||||
var details = result.Details is not null ? $" [grey]({Markup.Escape(result.Details)})[/]" : "";
|
||||
AnsiConsole.MarkupLine($" {icon} {Markup.Escape(result.Name)}{details}");
|
||||
|
||||
if (!result.Passed && result.DownloadUrl is not null)
|
||||
{
|
||||
AnsiConsole.MarkupLine($" [grey]Download: {result.DownloadUrl}[/]");
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Projects/BuildTool/Prerequisites/PrerequisiteResult.cs
Normal file
11
Projects/BuildTool/Prerequisites/PrerequisiteResult.cs
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
namespace BuildTool.Prerequisites;
|
||||
|
||||
public sealed class PrerequisiteResult
|
||||
{
|
||||
public required string Name { get; init; }
|
||||
public required bool Passed { get; init; }
|
||||
public string? Details { get; init; }
|
||||
public string? InstallCommand { get; init; }
|
||||
public string? DownloadUrl { get; init; }
|
||||
public bool IsWarning { get; init; }
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue