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


C# ConfigurationBuilder.AddCommandLine方法代码示例

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


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

示例1: Main

        public void Main(string[] args)
        {
            // Allow the location of the ini file to be specified via a --config command line arg
            var tempBuilder = new ConfigurationBuilder().AddCommandLine(args);
            var tempConfig = tempBuilder.Build();
            var configFilePath = tempConfig[ConfigFileKey] ?? HostingIniFile;

            var appBasePath = _serviceProvider.GetRequiredService<IApplicationEnvironment>().ApplicationBasePath;
            var builder = new ConfigurationBuilder(appBasePath);
            builder.AddIniFile(configFilePath, optional: true);
            builder.AddEnvironmentVariables();
            builder.AddCommandLine(args);
            var config = builder.Build();

            var host = new WebHostBuilder(_serviceProvider, config).Build();
            using (host.Start())
            {
                Console.WriteLine("Started");
                var appShutdownService = host.ApplicationServices.GetRequiredService<IApplicationShutdown>();
                Console.CancelKeyPress += (sender, eventArgs) =>
                {
                    appShutdownService.RequestShutdown();
                    // Don't terminate the process immediately, wait for the Main thread to exit gracefully.
                    eventArgs.Cancel = true;
                };
                appShutdownService.ShutdownRequested.WaitHandle.WaitOne();
            }
        }
开发者ID:humblelistener,项目名称:Hosting,代码行数:28,代码来源:Program.cs

示例2: 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:Giahim,项目名称:Brochard,代码行数:18,代码来源:Program.cs

示例3: 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(_serviceProvider, config)
                .UseServer("Microsoft.AspNet.Server.WebListener")
                .Build()
                .Start())
            {
                Console.WriteLine("Started the server..");
                Console.WriteLine("Press any key to stop the server");
                Console.ReadLine();
            }
            return Task.FromResult(0);
        }
开发者ID:rosslyn-cuongle,项目名称:MusicStore,代码行数:18,代码来源:Program.cs

示例4: Main

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

            var defaultSettings = new MemoryConfigurationSource();
            defaultSettings.Set("username", "Guest");
            builder.Add(defaultSettings);
            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.Get("username");

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


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