当前位置: 首页>>代码示例>>C#>>正文


C# ConfigurationBuilder.AddCommandLine方法代码示例

本文整理汇总了C#中Microsoft.Extensions.Configuration.ConfigurationBuilder.AddCommandLine方法的典型用法代码示例。如果您正苦于以下问题:C# ConfigurationBuilder.AddCommandLine方法的具体用法?C# ConfigurationBuilder.AddCommandLine怎么用?C# ConfigurationBuilder.AddCommandLine使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Microsoft.Extensions.Configuration.ConfigurationBuilder的用法示例。


在下文中一共展示了ConfigurationBuilder.AddCommandLine方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetDefault

        public static IConfiguration GetDefault(string[] args)
        {
            var configBuilder = new ConfigurationBuilder()
                .AddEnvironmentVariables();

            if (args != null)
            {
                configBuilder.AddCommandLine(args);
            }

            return configBuilder.Build();
        }
开发者ID:DamianReeves,项目名称:HalfWayTree,代码行数:12,代码来源:BusConfiguration.cs

示例2: Main

        public static void Main(string[] args)
        {
            var builder = new ConfigurationBuilder();
            builder.AddCommandLine(args);
            var config = builder.Build();

            using(var app = CreateWebHost(config))
            {
                var serverAddresses = app.ServerFeatures.Get<IServerAddressesFeature>();
                Console.BackgroundColor = ConsoleColor.Black;
                Console.WriteLine("I'm running... listen on {0}", string.Join(",", serverAddresses.Addresses));
                Console.ReadLine();
            }
        }
开发者ID:alienblog,项目名称:Rc,代码行数:14,代码来源:Program.cs

示例3: Startup

        /// <summary>
        /// Initializes a new instance of the <see cref="Startup"/> class.
        /// </summary>
        /// <param name="env"><see cref="IHostingEnvironment"/> instance.</param>
        /// <param name="args">List of arguments from the command line.</param>
        public Startup(IHostingEnvironment env, string[] args)
        {
            this.HostingEnvironment = env;

            var builder = new ConfigurationBuilder()
                .AddJsonFile("appsettings.json")
                .AddEnvironmentVariables();

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

            this.Configuration = builder.Build();
        }
开发者ID:haruair,项目名称:Scissorhands.NET,代码行数:20,代码来源:Startup.cs

示例4: GetDefault

        public static IConfiguration GetDefault(string[] args)
        {
            // We are adding all environment variables first and then adding the ASPNET_ ones
            // with the prefix removed to unify with the command line and config file formats
            var configBuilder = new ConfigurationBuilder()
                .AddJsonFile(HostingJsonFile, optional: true)
                .AddEnvironmentVariables()
                .AddEnvironmentVariables(prefix: EnvironmentVariablesPrefix);

            if (args != null)
            {
                configBuilder.AddCommandLine(args);
            }

            return configBuilder.Build();
        }
开发者ID:leloulight,项目名称:Hosting,代码行数:16,代码来源:WebApplicationConfiguration.cs

示例5: Main

        public static void Main(string[] args)
        {
            //Add command line configuration source to read command line parameters.
            var builder = new ConfigurationBuilder();
            builder.AddCommandLine(args);
            var config = builder.Build();

            using (new WebHostBuilder(config)
                .UseServer("Microsoft.AspNet.Server.WebListener")
                .Build()
                .Start())
            {
                Console.WriteLine("Started the server..");
                Console.WriteLine("Press any key to stop the server");
                Console.ReadLine();
            }
        }
开发者ID:adwardliu,项目名称:MusicStore,代码行数:17,代码来源:Program.cs

示例6: Main

        //https://github.com/aspnet/Hosting/blob/dev/src/Microsoft.AspNet.Hosting/Program.cs
        public Task<int> Main(string[] args)
        {
            //Add command line configuration source to read command line parameters.
            var builder = new ConfigurationBuilder();
            builder.AddCommandLine(args);
            var config = builder.Build();

            var webhost = new WebHostBuilder(_serviceProvider, config)
                .UseServer("Microsoft.AspNet.Server.WebListener")
                .Build();
            using (var host = webhost.Start()) {
                var orchardHost = new OrchardHost(webhost.ApplicationServices, System.Console.In, System.Console.Out, args);

                return Task.FromResult(
                    (int)orchardHost.Run());
            }
        }
开发者ID:284247028,项目名称:Brochard,代码行数:18,代码来源:Program.cs

示例7: Main

        public Task<int> Main(string[] args)
        {
            //Add command line configuration source to read command line parameters.
            var builder = new ConfigurationBuilder();
            builder.AddCommandLine(args);
            var config = builder.Build();

            using (new WebHostBuilder(config)
                .UseServer("Microsoft.AspNet.Server.Kestrel")
                .Build()
                .Start())
            {
                Console.WriteLine("Started the server..");
                Console.WriteLine("Press any key to stop the server");
                Console.ReadLine();
            }
            return Task.FromResult(0);
        }
开发者ID:ChujianA,项目名称:aspnetcore-doc-cn,代码行数:18,代码来源:Program.cs

示例8: Main

        public void Main(string[] args)
        {
            var builder = new ConfigurationBuilder();
            Console.WriteLine("Initial Config Providers: " + builder.Providers.Count());

            var defaultSettings = new MemoryConfigurationProvider();
            defaultSettings.Set("username", "Guest");
            builder.Add(defaultSettings);
            Console.WriteLine("Added Memory Provider. Providers: " + builder.Providers.Count());

            builder.AddCommandLine(args);
            Console.WriteLine("Added Command Line Provider. Providers: " + builder.Providers.Count());

            var config = builder.Build();
            string username = config["username"];

            Console.WriteLine($"Hello, {username}!");
        }
开发者ID:ChujianA,项目名称:aspnetcore-doc-cn,代码行数:18,代码来源:Program.cs

示例9: Startup

        public Startup(IApplicationEnvironment applicationEnvironment)
        {
            var configBuilder = new ConfigurationBuilder()
                .SetBasePath(applicationEnvironment.ApplicationBasePath)
                .AddJsonFile("config.json", optional: true)
                .AddEnvironmentVariables();

            if (Program.Environment.OtherArgs != null)
            {
                configBuilder.AddCommandLine(Program.Environment.OtherArgs);
            }

            // Use the local omnisharp config if there's any in the root path
            if (File.Exists(Program.Environment.ConfigurationPath))
            {
                configBuilder.AddJsonFile(Program.Environment.ConfigurationPath);
            }

            Configuration = configBuilder.Build();
        }
开发者ID:RLittlesII,项目名称:omnisharp-roslyn,代码行数:20,代码来源:Startup.cs

示例10: Main

        public static void Main(string[] args)
        {
            var builder = new ConfigurationBuilder();
            Console.WriteLine("Initial Config Sources: " + builder.Sources.Count());

            builder.AddInMemoryCollection(new Dictionary<string, string>
            {
                { "username", "Guest" }
            });

            Console.WriteLine("Added Memory Source. Sources: " + builder.Sources.Count());

            builder.AddCommandLine(args);
            Console.WriteLine("Added Command Line Source. Sources: " + builder.Sources.Count());

            var config = builder.Build();
            string username = config["username"];

            Console.WriteLine($"Hello, {username}!");
        }
开发者ID:ColinDabritz,项目名称:Docs,代码行数:20,代码来源:Program.cs

示例11: Main

        public static void Main(string[] args)
        {
            var configurationBuilder = new ConfigurationBuilder();
            configurationBuilder.AddJsonFile("appsettings.json");
            configurationBuilder.AddCommandLine(args);
            configurationBuilder.AddEnvironmentVariables();
            var configuration = configurationBuilder.Build();

            var backgroundColor = (ConsoleColor) short.Parse(configuration["Console:Background:Color"]);
            var foregroundColor = (ConsoleColor) short.Parse(configuration["Console:Foreground:Color"]);

            Console.BackgroundColor = backgroundColor;
            Console.ForegroundColor = foregroundColor;

            Console.WriteLine($"The foreground color is {foregroundColor}");
            Console.WriteLine($"The background color is {backgroundColor}");
            Console.WriteLine(Environment.NewLine);
            Console.WriteLine("Press 'Enter' to exit...");
            Console.ReadLine();
        }
开发者ID:JHilmarch,项目名称:CoreConfig,代码行数:20,代码来源:Program.cs

示例12: AddConfigServer_CommandLineAppSettingsConfiguresClient

        public void AddConfigServer_CommandLineAppSettingsConfiguresClient()
        {
            // Arrange
            var appsettings = new string[]
                {
                    "spring:cloud:config:enabled=false",
                    "--spring:cloud:config:failFast=false",
                    "/spring:cloud:config:uri=http://foo.com:9999",
                    "--spring:cloud:config:name", "myName",
                    "/spring:cloud:config:label", "myLabel",
                    "--spring:cloud:config:username", "myUsername",
                    "--spring:cloud:config:password", "myPassword"
                };

            var configurationBuilder = new ConfigurationBuilder();
            var environment = new HostingEnvironment();
            configurationBuilder.AddCommandLine(appsettings);

            // Act and Assert
            configurationBuilder.AddConfigServer(environment);

            ConfigServerConfigurationProvider configServerProvider = null;
            foreach (IConfigurationProvider provider in configurationBuilder.Providers)
            {
                configServerProvider = provider as ConfigServerConfigurationProvider;
                if (configServerProvider != null)
                    break;
            }
            Assert.NotNull(configServerProvider);
            ConfigServerClientSettings settings = configServerProvider.Settings;

            Assert.False(settings.Enabled);
            Assert.False(settings.FailFast);
            Assert.Equal("http://foo.com:9999", settings.Uri);
            Assert.Equal(ConfigServerClientSettings.DEFAULT_ENVIRONMENT, settings.Environment);
            Assert.Equal("myName", settings.Name );
            Assert.Equal("myLabel", settings.Label );
            Assert.Equal("myUsername", settings.Username);
            Assert.Equal("myPassword", settings.Password );
        }
开发者ID:sdougherty,项目名称:Configuration,代码行数:40,代码来源:ConfigServerConfigurationExtensionsTest.cs

示例13: Main

        public static void Main(string[] args)
        {
            var baseConfigBuilder = new ConfigurationBuilder();
            baseConfigBuilder.SetBasePath(Directory.GetCurrentDirectory());
            baseConfigBuilder.AddCommandLine(args);
            baseConfigBuilder.AddEnvironmentVariables();
            var configFile = baseConfigBuilder.Build()["config"];
            if (string.IsNullOrEmpty(configFile))
            {
                Console.WriteLine("No Config File");
                Console.WriteLine("Need Parameter \"--config path\"");
                return;
            }
            baseConfigBuilder.AddJsonFile(configFile, true, true);
            var baseConfig = baseConfigBuilder.Build();
            var logConfigFile = baseConfig["Data:LogConfig"];
            var notifyAppsConfigFile = baseConfig["Data:NotifyAppsConfig"];
            var appChannelConfigFile = baseConfig["Data:AppChannelConfig"];
            baseConfigBuilder
                .AddJsonFile(logConfigFile, true, true)
                .AddJsonFile(notifyAppsConfigFile, true, true)
                .AddJsonFile(appChannelConfigFile, true, true);
            Configuration = baseConfigBuilder.Build();

            //Nlog
            var nlogConfig = new NLog.Config.LoggingConfiguration();
            BahamutCommon.LoggerLoaderHelper.LoadLoggerToLoggingConfig(nlogConfig, Configuration, "Logger:fileLoggers");

            #if DEBUG
            BahamutCommon.LoggerLoaderHelper.AddConsoleLoggerToLogginConfig(nlogConfig);
            #endif
            LogManager.Configuration = nlogConfig;

            try
            {
                //CSServer
                var server = new ChicagoServer();
                Server = server;
                server.UseNetConfig(new NetConfigReader());
                server.UseServerConfig(new ServerConfigReader());
                server.UseLogger(new FileLogger(Configuration["ServerLog"]));
            #if DEBUG
                server.UseLogger(ConsoleLogger.Instance);
            #endif
                server.UseMessageRoute(new JsonRouteFilter());
                server.UseExtension(new BahamutUserValidationExtension());
                server.UseExtension(new SharelinkerValidateExtension());
                server.UseExtension(new BahamutAppValidateExtension());

                //NotificationCenter Extension
                var notificationExt = new NotificaionCenterExtension();
                server.UseExtension(notificationExt);
                server.UseExtension(new HeartBeatExtension());
                server.StartServer();
            #if DEBUG
                DebugConsole();
            #else
                Thread.Sleep(Timeout.Infinite);
            #endif
            }
            catch (Exception ex)
            {
                LogManager.GetLogger("Chicago").Fatal(ex);
                throw;
            }
        }
开发者ID:Sharelink,项目名称:Chicago,代码行数:66,代码来源:Program.cs


注:本文中的Microsoft.Extensions.Configuration.ConfigurationBuilder.AddCommandLine方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。