ASP.NETCore_配置_命令行

2025-02-03 11:52:52

1、1 打开vs2017 点击菜单新建

ASP.NETCore_配置_命令行

2、1选择.netcore2选择控制台应用3填写项目名称4确定

ASP.NETCore_配置_命令行

3、1管理nuget包2安装 microsoft.aspnetcore.all

ASP.NETCore_配置_命令行ASP.NETCore_配置_命令行

4、代码:using Microsoft.Extensions.Configuration;using System;using System.Collections.Generic;namespace ASPNETCORE_命令行配置{ class Program { static void Main(string[] args) { //配置都是基于键值对 var settings = new Dictionary<string, string> { { "banji", "444" }, { "renshu", "1444" } }; //构建配置建造对象 var builder = new ConfigurationBuilder() .AddInMemoryCollection(settings);//配置 var configuration = builder.Build(); Console.WriteLine($"banji:{configuration["banji"]}");//输出配置 Console.WriteLine($"renshu: {configuration["renshu"]}");//输出配置 Console.ReadLine();//等待 } }}

ASP.NETCore_配置_命令行

5、运行完成

ASP.NETCore_配置_命令行
猜你喜欢