ConfigurationManager.AppSettings是否在.NET Core 2.0中可用?
我有一个从我的配置文件中读取设置的方法,如下所示:
var value = ConfigurationManager.AppSettings[key];
只针对.NET Standard 2.0时,它编译得很好。
现在我需要多个目标,所以我用以下内容更新了我的项目文件:
netcoreapp2.0;net461;netstandard2.0
但是现在, netcoreapp2.0
的编译失败, netcoreapp2.0
以下错误消息:
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
。
我很困惑因为它在.NET Standard 2.0下可用,所以我希望它可以在.NET Core 2.0中使用,因为.NET Core 2.0符合.NET Standard 2.0。
我错过了什么?
是的,在引用NuGet包System.Configuration.ConfigurationManager
之后, ConfigurationManager.AppSettings
在.NET Core 2.0中可用。
积分转到@JeroenMostert给我解决方案。