Ich versuche Appsettings Transformation zu einer .net-Core-2-Konsole-Anwendung hinzuzufügen, z..Net Core 2 Konsole Appsettings transformieren
- appSettings.json
- appSettings.Test.json
- appSettings.Prod.json
ich den folgenden Code gefunden haben, für asp.net Kern funktioniert:
public Startup(IHostingEnvironment env)
{
var builder = new ConfigurationBuilder()
.SetBasePath(env.ContentRootPath)
.AddJsonFile("appsettings.json", optional: false, reloadOnChange:
true)
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional:
true)
.AddEnvironmentVariables();
Configuration = builder.Build();
}
Ich weiß jedoch nicht, wie man env.EnvironmentName
bekommt, weil es keine IHostingEnvironment
in einer Konsolen-App gibt.
Jede Hilfe wird
Mögliche Duplikat [jetzt klar sein, Verwenden von Start up-Klasse in ASP.NET5-Konsolenanwendung] (https://stackoverflow.com/questions/30257710/using-startup-class-in-asp-net5-console-application#30259936) – CalC
Dies ist kein Duplikat, da IApplicationEnvironment jetzt hat wurde entfernt https://github.com/aspnet/PlatformAbstractions/issues/37 –
Und 'Microsoft.Extensions.PlatformAbstractions.PlatformServices.Default.Application' enthält keine Umgebungsinformationen –