我正在尝试创建一个自包含的.NET Core控制台应用程序。 在我的应用程序中,我添加了一个配置文件appsettings.json。 目标是现在我需要有可能修改配置文件,而应用程序正在运行(和公布)更改ASP.NET Core中的配置文件
我发现了几个指南,但他们都指向我需要包括以下功能的方向:
public void ConfigureServices(IServiceCollection services)
{
// Adds services required for using options.
services.AddOptions();
// Register the IConfiguration instance which MyOptions binds against.
services.Configure<DBSetting>(Configuration);
// Add framework services.
services.AddMvc();
}
但是当我做这一切服务的methodes是红色的。如果我看着你IserviceCollection,文档说它已经过时了。 我确实在我的Program.cs这让我在我的配置文件读取数据添加
var builder = new ConfigurationBuilder()
.AddJsonFile(@"C:\Users\Maarten\Documents\Visual Studio 2015\Projects\CorporationBot\CorporationBotCore\appsettings.json", optional: true, reloadOnChange:true);
Configuration = builder.Build();
。 现在我需要一种方法来在应用程序运行时更改我的配置。 任何最新的方法来做到这一点?
什么版本的.NET核心吗?你在'.csproj'文件中有什么依赖关系? – omajid