将AppSettings文件添加到.NET标准库

时间:2017-05-22 20:54:57

标签: c# xamarin asp.net-core .net-standard

我正在尝试将appsettings.json文件添加到.NET Standard库中,并且我一直在遇到文件放置位置以及如何访问它的问题。我在名为AppSettings.cs的文件夹中有一个名为Settings的文件,构造函数中包含以下代码。

private AppSettings()
{
    var builder = new ConfigurationBuilder()
        .SetBasePath(".")
        .AddJsonFile(APP_SETTINGS_FILE);
    configuration = builder.Build();
}

但是,我似乎无法使基本路径正确。我尝试使用它而不是“。”获取我当前所在的目录,但

中的GetEntryAssembly()
string assemblyFile = (new System.Uri(Assembly.GetEntryAssembly().CodeBase)).AbsolutePath;
.NET Standard似乎不支持

。我一直在使用控制台应用程序对此进行测试,我希望稍后将该库用于Xamarin项目或.NET Core应用程序。这样做甚至可能,或者我错过了一些事情。谢谢你的帮助。

0 个答案:

没有答案