diff --git a/Data_Coupler/Data_Coupler.csproj b/Data_Coupler/Data_Coupler.csproj index 67297cc..0f7be6e 100644 --- a/Data_Coupler/Data_Coupler.csproj +++ b/Data_Coupler/Data_Coupler.csproj @@ -29,4 +29,10 @@ + + + PreserveNewest + + + diff --git a/Data_Coupler/Services/VersionService.cs b/Data_Coupler/Services/VersionService.cs index b70aa90..9a45ce7 100644 --- a/Data_Coupler/Services/VersionService.cs +++ b/Data_Coupler/Services/VersionService.cs @@ -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(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)