## 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" />
212 lines
5.9 KiB
C#
212 lines
5.9 KiB
C#
using System.Runtime.InteropServices;
|
|
using BuildTool.Publishing;
|
|
|
|
namespace BuildTool.Platform;
|
|
|
|
public static class PlatformDetector
|
|
{
|
|
// Windows 11 starts at build 22000
|
|
private const int Windows11MinBuild = 22000;
|
|
|
|
public static PlatformInfo Detect()
|
|
{
|
|
var osRid = GetOsRid();
|
|
var archRid = GetArchRid();
|
|
var (distroId, distroName) = GetLinuxDistroInfo();
|
|
var kernelVersion = GetKernelVersion(osRid);
|
|
var osName = GetOsDisplayName(osRid, distroName, kernelVersion);
|
|
var packageManager = DetectPackageManager(osRid, distroId);
|
|
|
|
return new PlatformInfo
|
|
{
|
|
OsName = osName,
|
|
OsRid = osRid,
|
|
ArchRid = archRid,
|
|
DistroId = distroId,
|
|
DistroName = distroName,
|
|
KernelVersion = kernelVersion,
|
|
PackageManager = packageManager
|
|
};
|
|
}
|
|
|
|
private static string GetOsDisplayName(string osRid, string? distroName, string? kernelVersion)
|
|
{
|
|
if (OperatingSystem.IsWindows())
|
|
{
|
|
var version = Environment.OSVersion.Version;
|
|
var windowsVersion = version.Build >= Windows11MinBuild ? "11" : "10";
|
|
return $"Windows {windowsVersion} (Build {version.Build})";
|
|
}
|
|
|
|
if (OperatingSystem.IsMacOS())
|
|
{
|
|
var version = Environment.OSVersion.Version;
|
|
var macosName = GetMacOSCodename(version.Major);
|
|
return macosName is not null
|
|
? $"macOS {version.Major}.{version.Minor} {macosName}"
|
|
: $"macOS {version.Major}.{version.Minor}";
|
|
}
|
|
|
|
// Linux: show distro name with kernel version
|
|
if (distroName is not null && kernelVersion is not null)
|
|
{
|
|
return $"{distroName} (kernel {kernelVersion})";
|
|
}
|
|
|
|
return distroName ?? (kernelVersion is not null ? $"Linux (kernel {kernelVersion})" : "Linux");
|
|
}
|
|
|
|
private static string? GetMacOSCodename(int majorVersion) =>
|
|
majorVersion switch
|
|
{
|
|
15 => "Sequoia",
|
|
14 => "Sonoma",
|
|
13 => "Ventura",
|
|
12 => "Monterey",
|
|
_ => null
|
|
};
|
|
|
|
private static string GetOsRid()
|
|
{
|
|
if (OperatingSystem.IsWindows())
|
|
{
|
|
return "win";
|
|
}
|
|
|
|
if (OperatingSystem.IsMacOS())
|
|
{
|
|
return "osx";
|
|
}
|
|
|
|
return "linux";
|
|
}
|
|
|
|
private static string GetArchRid() =>
|
|
RuntimeInformation.ProcessArchitecture switch
|
|
{
|
|
Architecture.X64 => "x64",
|
|
Architecture.Arm64 => "arm64",
|
|
_ => "x64"
|
|
};
|
|
|
|
private static string? GetKernelVersion(string osRid)
|
|
{
|
|
if (osRid != "linux")
|
|
{
|
|
return null;
|
|
}
|
|
|
|
// Try /proc/version first (most reliable)
|
|
if (File.Exists("/proc/version"))
|
|
{
|
|
try
|
|
{
|
|
var procVersion = File.ReadAllText("/proc/version");
|
|
// Format: "Linux version 6.5.0-44-generic ..."
|
|
var parts = procVersion.Split(' ', StringSplitOptions.RemoveEmptyEntries);
|
|
if (parts.Length >= 3 && parts[0] == "Linux" && parts[1] == "version")
|
|
{
|
|
return parts[2];
|
|
}
|
|
}
|
|
catch
|
|
{
|
|
// Fall through to uname
|
|
}
|
|
}
|
|
|
|
// Fall back to uname -r
|
|
var result = ProcessRunner.RunCaptured("uname", "-r");
|
|
return result.Success ? result.StandardOutput.Trim() : null;
|
|
}
|
|
|
|
private static (string? Id, string? Name) GetLinuxDistroInfo()
|
|
{
|
|
if (!OperatingSystem.IsLinux())
|
|
{
|
|
return (null, null);
|
|
}
|
|
|
|
const string osReleasePath = "/etc/os-release";
|
|
if (!File.Exists(osReleasePath))
|
|
{
|
|
return (null, null);
|
|
}
|
|
|
|
string? id = null;
|
|
string? name = null;
|
|
|
|
foreach (var line in File.ReadLines(osReleasePath))
|
|
{
|
|
if (line.StartsWith("ID=", StringComparison.Ordinal))
|
|
{
|
|
id = line[3..].Trim('"');
|
|
}
|
|
else if (line.StartsWith("PRETTY_NAME=", StringComparison.Ordinal))
|
|
{
|
|
name = line[12..].Trim('"');
|
|
}
|
|
|
|
if (id is not null && name is not null)
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
|
|
return (id, name);
|
|
}
|
|
|
|
private static PackageManager DetectPackageManager(string osRid, string? distroId)
|
|
{
|
|
if (osRid == "osx")
|
|
{
|
|
return PackageManager.Brew;
|
|
}
|
|
|
|
if (osRid != "linux")
|
|
{
|
|
return PackageManager.Unknown;
|
|
}
|
|
|
|
// Check distro ID first for accuracy
|
|
return distroId?.ToLowerInvariant() switch
|
|
{
|
|
"ubuntu" or "debian" or "linuxmint" or "pop" or "elementary" or "zorin" => PackageManager.Apt,
|
|
"fedora" or "centos" or "rhel" or "rocky" or "alma" or "ol" => PackageManager.Dnf,
|
|
"opensuse" or "opensuse-leap" or "opensuse-tumbleweed" or "sles" => PackageManager.Zypper,
|
|
"arch" or "manjaro" or "endeavouros" => PackageManager.Pacman,
|
|
"alpine" => PackageManager.Apk,
|
|
_ => DetectPackageManagerFromBinaries()
|
|
};
|
|
}
|
|
|
|
private static PackageManager DetectPackageManagerFromBinaries()
|
|
{
|
|
if (File.Exists("/usr/bin/apt-get") || File.Exists("/usr/bin/apt"))
|
|
{
|
|
return PackageManager.Apt;
|
|
}
|
|
|
|
if (File.Exists("/usr/bin/dnf"))
|
|
{
|
|
return PackageManager.Dnf;
|
|
}
|
|
|
|
if (File.Exists("/usr/bin/zypper"))
|
|
{
|
|
return PackageManager.Zypper;
|
|
}
|
|
|
|
if (File.Exists("/usr/bin/pacman"))
|
|
{
|
|
return PackageManager.Pacman;
|
|
}
|
|
|
|
if (File.Exists("/sbin/apk"))
|
|
{
|
|
return PackageManager.Apk;
|
|
}
|
|
|
|
return PackageManager.Unknown;
|
|
}
|
|
}
|