refactor: AppPaths.WwwRoot – zentrale wwwroot-Pfadauflösung
- Neue statische Klasse AppPaths mit WwwRoot-Property - Dev-Modus: ../../../wwwroot (Quell-Verzeichnis) - Publish-Modus: Fallback auf BaseDirectory/wwwroot - Program.cs + RemoteEndpoint.cs nutzen AppPaths statt eigener Logik
This commit is contained in:
1 parent
49ef6bedc6
commit
ab64a843fc
3 files changed
+32
-4
No files matched your search
@@ -0,0 +1,28 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
namespace Gott.Services;
|
||||
|
||||
/// <summary>
|
||||
/// Zentrale Pfade der Anwendung. Werden beim Start in Program.cs gesetzt.
|
||||
/// </summary>
|
||||
public static class AppPaths
|
||||
{
|
||||
/// <summary>
|
||||
/// Absoluter Pfad zum wwwroot-Verzeichnis.
|
||||
/// Im Dev-Modus das Quell-Verzeichnis (../../../wwwroot),
|
||||
/// im Publish-Modus das Verzeichnis neben der Executable.
|
||||
/// </summary>
|
||||
public static string WwwRoot { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Initialisiert die Pfade. Wird einmal beim Start aufgerufen.
|
||||
/// </summary>
|
||||
public static void Initialize()
|
||||
{
|
||||
var devPath = Path.GetFullPath(Path.Combine(AppContext.BaseDirectory, "..", "..", "..", "wwwroot"));
|
||||
WwwRoot = Directory.Exists(devPath)
|
||||
? devPath
|
||||
: Path.Combine(AppContext.BaseDirectory, "wwwroot");
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user