![](/img/trans.png)
[英]c# .Net Core 3.1 Azure App Service Windows - Application not able to retrieve App settings
[英]how to save settings in c# .net core 3.1 console application?
目前,該文件包含我在應用程序代碼運行后分配的一個日期時間屬性:
像往常一樣,我按如下方式分配屬性:
static void Main(string[] args)
{
Properties.Default.LastUpdate = DateTime.Now;
}
問題
通常,我會將設置保存到文件中,如下所示,但出於某種原因,VS 不喜歡它:
根據要求的完整代碼:
static void Main(string[] args)
{
Properties.Default.LastUpdate = DateTime.Now;
Properties.Default.Save();
Properties.Default.Reload();
}
我建議使用 .net 內核提供的新配置選項。
-> 將 appsettings.json 添加到您的項目中
appsettings.json
{
"name" : "Gary"
}
在里面
IConfiguration config = new ConfigurationBuilder()
.AddJsonFile("appsettings.json", true, true)
.Build();
在本次討論中,您還將找到一種如何在運行時更新值的方法:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.