コード例 #1
0
        public static IHostBuilder UseEnvironment(this IHostBuilder hostBuilder, string[] args)
        {
            return(hostBuilder.ConfigureHostConfiguration(configBuilder =>
            {
                configBuilder.AddEnvironmentVariables("DOTNETCORE_");

                args = CmdArgHelper.WithoutShortSwitches(args);

                if (args != null && args.Length > 0)
                {
                    configBuilder.AddCommandLine(args);
                }
            }));
        }
コード例 #2
0
        public static IConfigurationBuilder AddAppSettings(this IConfigurationBuilder bldr, IHostingEnvironment env, string[] args = null, bool optional = true, bool reloadOnChange = false)
        {
            var envName = env.EnvironmentName;

            bldr.SetBasePath(AppContext.BaseDirectory)
            .AddJsonFile("appsettings.json", optional, reloadOnChange)
            .AddJsonFile($"appsettings.{envName}.json", optional, reloadOnChange);

            if (env.IsDevelopment())
            {
                bldr.AddUserSecrets(System.Reflection.Assembly.GetEntryAssembly(), optional: true);
            }

            args = CmdArgHelper.WithoutShortSwitches(args, false);

            if (args != null && args.Length > 0)
            {
                bldr.AddCommandLine(args);
            }

            return(bldr);
        }
コード例 #3
0
 public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
 WebHost.CreateDefaultBuilder(CmdArgHelper.WithoutShortSwitches(args))
 .UseStartup <Startup>()
 .UseSerilogFromConfig();