fix: parse version.json instead of version.txt in Program.cs
TaxBaik CI/CD / build-and-deploy (push) Successful in 49s
TaxBaik CI/CD / build-and-deploy (push) Successful in 49s
- CI/CD generates version.json (JSON format) but Program.cs was parsing version.txt - Update version loading to read from version.json - Add error handling for JSON parsing Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
+13
-8
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user