我有appsettings.json
,构建操作设置为Embedded Resource
。我通常会提取文件并按如下所示制作新副本。
string jsonFullPath = Path.Combine(FileSystem.AppDataDirectory, "namespace.directory.appsettings.json");
Assembly assembly = Assembly.GetExecutingAssembly();
using (Stream resourceFileStream = assembly.GetManifestResourceStream(resourceFilename))
{
if (resourceFileStream != null)
{
using (FileStream fileStream = File.Create(jsonFullPath))
{
resourceFileStream.CopyTo(fileStream);
}
}
}
并将副本添加到ConfigurationBuilder
的实例,如下所示。
Configuration = new ConfigurationBuilder()
.AddJsonFile(jsonFullPath, optional: true, reloadOnChange: true)
.Build();
是否可以使ConfigurationBuilder
直接使用嵌入式JSON文件,而无需像我上面那样创建新的临时文件?如果是,该怎么办?