1 Commits

Author SHA1 Message Date
Alessio Dal Santo e7fb9a5cc7 fix: Corretto caricamento version.json con percorso robusto e copia automatica in output 2026-02-02 12:27:38 +01:00
2 changed files with 32 additions and 5 deletions
+6
View File
@@ -29,4 +29,10 @@
</PackageReference> </PackageReference>
</ItemGroup> </ItemGroup>
<ItemGroup>
<Content Update="wwwroot\version.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
</Project> </Project>
+26 -5
View File
@@ -43,10 +43,30 @@ namespace Data_Coupler.Services
{ {
try try
{ {
// Cerca il file version.json nella root dell'applicazione // Cerca il file version.json nella cartella wwwroot o nella root del progetto
var versionFilePath = Path.Combine(_env.ContentRootPath, "version.json"); 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 json = File.ReadAllText(versionFilePath);
var version = JsonSerializer.Deserialize<VersionInfo>(json, new JsonSerializerOptions var version = JsonSerializer.Deserialize<VersionInfo>(json, new JsonSerializerOptions
@@ -56,13 +76,14 @@ namespace Data_Coupler.Services
if (version != null) if (version != null)
{ {
_logger.LogInformation("Version loaded: {Version}", version.GetFullVersion()); _logger.LogInformation("Version loaded from {Path}: {Version}", versionFilePath, version.GetFullVersion());
return version; return version;
} }
} }
else 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) catch (Exception ex)