.NET Core 2.0中是否提供ConfigurationManager.AppSettings? [英] Is ConfigurationManager.AppSettings available in .NET Core 2.0?
问题描述
我有一种方法可以从我的配置文件中读取设置,如下所示:
I've got a method that reads settings from my config file like this:
var value = ConfigurationManager.AppSettings[key];
仅面向.NET Standard 2.0时,编译良好。
It compiles fine when targeting .NET Standard 2.0 only.
现在我需要多个目标,因此我用以下项目更新了项目文件:
Now I need multiple targets, so I updated my project file with:
<TargetFrameworks>netcoreapp2.0;net461;netstandard2.0</TargetFrameworks>
但是现在, netcoreapp2.0 $ c $的编译失败c>,并显示以下错误消息:
But now, the compilation fails for netcoreapp2.0
with the following error message:
Error CS0103 The name 'ConfigurationManager' does not exist in the current context (netcoreapp2.0)
我分别创建了一个新的.NET Core 2.0控制台应用程序(仅针对.NET Core 2.0时间),但同样在名称空间 System.Configuration
下似乎没有 ConfigurationManager
。
Separately, I created a new .NET Core 2.0 console application (only targeting .NET Core 2.0 this time), but likewise there seems to be no ConfigurationManager
under the namespace System.Configuration
.
我很困惑,因为它可以在.NET Standard 2.0下使用,所以我希望它可以在.NET Core 2.0中使用,就像.NET Core 2.0一样。符合NET Standard 2.0。
I'm quite confused because it's available under .NET Standard 2.0, so I would expect it to be available in .NET Core 2.0, as .NET Core 2.0 is .NET Standard 2.0 compliant.
我想念什么?
推荐答案
是的,.NET Core 2.0中提供了 ConfigurationManager.AppSettings
在引用NuGet包 System.Configuration.ConfigurationManager
之后。
Yes, ConfigurationManager.AppSettings
is available in .NET Core 2.0 after referencing NuGet package System.Configuration.ConfigurationManager
.
信用归@JeroenMostert提供给我解决方案。
Credits goes to @JeroenMostert for giving me the solution.
这篇关于.NET Core 2.0中是否提供ConfigurationManager.AppSettings?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!