diff --git a/TaxBaik.Web/Program.cs b/TaxBaik.Web/Program.cs index ea39953..26808e9 100644 --- a/TaxBaik.Web/Program.cs +++ b/TaxBaik.Web/Program.cs @@ -85,16 +85,21 @@ builder.Services.AddApplication(); // Register version info var versionInfo = new VersionInfo(); -var versionFilePath = Path.Combine(AppContext.BaseDirectory, "wwwroot", "version.txt"); -if (File.Exists(versionFilePath)) +var versionJsonPath = Path.Combine(AppContext.BaseDirectory, "wwwroot", "version.json"); +if (File.Exists(versionJsonPath)) { - var lines = File.ReadAllLines(versionFilePath); - foreach (var line in lines) + try { - if (line.StartsWith("Version:")) - versionInfo.Version = line.Substring("Version:".Length).Trim(); - else if (line.StartsWith("Built:")) - versionInfo.Built = line.Substring("Built:".Length).Trim(); + var json = System.Text.Json.JsonDocument.Parse(File.ReadAllText(versionJsonPath)); + var root = json.RootElement; + if (root.TryGetProperty("version", out var versionProp)) + versionInfo.Version = versionProp.GetString() ?? "unknown"; + if (root.TryGetProperty("built", out var builtProp)) + versionInfo.Built = builtProp.GetString() ?? "unknown"; + } + catch (Exception ex) + { + Console.WriteLine($"Warning: Failed to parse version.json: {ex.Message}"); } } builder.Services.AddSingleton(versionInfo);