public static async Task Main(string[] args) { var cupsKeySettings = EnvironmentSettings.Create().ToList(); string environmentName; string configPath; string configFile; SetManifestFilePath(); var builder = new HostBuilder() .ConfigureAppConfiguration((hostingContext, config) => { var env = hostingContext.HostingEnvironment; env.EnvironmentName = environmentName; config.SetBasePath(configPath); config.AddYamlFile(configFile, optional: true); config.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true); config.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true); config.AddEnvironmentVariables(); config.AddInMemoryCollection(cupsKeySettings); if (args != null) { config.AddCommandLine(args); } }) .ConfigureServices((hostContext, services) => { services.AddOptions(); services.Configure <ToggleSettings>(hostContext.Configuration.GetSection("ToggleSettings")); services.Configure <GdasServiceSettings>(hostContext.Configuration.GetSection("GdasServiceSettings")); services.AddHostedService <Startup>(); //services.AddMvcCore().SetCompatibilityVersion(CompatibilityVersion.Version_2_1); }) .ConfigureLogging((hostingContext, logging) => { logging.AddConfiguration(hostingContext.Configuration.GetSection("Logging")); logging.AddConsole(); }); //services.Configure<AppConfig>(hostContext.Configuration.GetSection("AppConfig")); //services.AddSingleton<IHostedService, PrintTextToConsoleService>(); await builder.RunConsoleAsync(); void SetManifestFilePath() { environmentName = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") ?? "Development"; configPath = Path.Combine(Environment.CurrentDirectory); configFile = "manifest.yml"; } }
public Startup(IHostingEnvironment env) { var cupsKeySettings = EnvironmentSettings.Create().ToList(); var builder = new ConfigurationBuilder() .SetBasePath(env.ContentRootPath) .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true) .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true) .AddInMemoryCollection(cupsKeySettings); Configuration = builder.Build(); }