fix: Corretto caricamento version.json con percorso robusto e copia automatica in output

This commit is contained in:
Alessio Dal Santo
2026-02-02 12:27:38 +01:00
parent e1f7f919a2
commit e7fb9a5cc7
2 changed files with 32 additions and 5 deletions
+26 -5
View File
@@ -43,10 +43,30 @@ namespace Data_Coupler.Services
{
try
{
// Cerca il file version.json nella root dell'applicazione
var versionFilePath = Path.Combine(_env.ContentRootPath, "version.json");
// Cerca il file version.json nella cartella wwwroot o nella root del progetto
string? versionFilePath = null;
// Prima prova in wwwroot
if (!string.IsNullOrEmpty(_env.WebRootPath))
{
var wwwrootPath = Path.Combine(_env.WebRootPath, "version.json");
if (File.Exists(wwwrootPath))
{
versionFilePath = wwwrootPath;
}
}
// Se non trovato, prova nella root del progetto
if (versionFilePath == null)
{
var contentPath = Path.Combine(_env.ContentRootPath, "wwwroot", "version.json");
if (File.Exists(contentPath))
{
versionFilePath = contentPath;
}
}
if (File.Exists(versionFilePath))
if (versionFilePath != null && File.Exists(versionFilePath))
{
var json = File.ReadAllText(versionFilePath);
var version = JsonSerializer.Deserialize<VersionInfo>(json, new JsonSerializerOptions
@@ -56,13 +76,14 @@ namespace Data_Coupler.Services
if (version != null)
{
_logger.LogInformation("Version loaded: {Version}", version.GetFullVersion());
_logger.LogInformation("Version loaded from {Path}: {Version}", versionFilePath, version.GetFullVersion());
return version;
}
}
else
{
_logger.LogWarning("version.json not found at {Path}, using default version", versionFilePath);
_logger.LogWarning("version.json not found. Searched in WebRootPath: {WebRoot}, ContentRootPath: {ContentRoot}",
_env.WebRootPath ?? "null", _env.ContentRootPath);
}
}
catch (Exception ex)