I have appsettings.json with build action set to Embedded Resource. I usually extract the file and make a new copy of it as follows.
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);
}
}
}
And add the copy to an instance of ConfigurationBuilder as follows.
Configuration = new ConfigurationBuilder()
.AddJsonFile(jsonFullPath, optional: true, reloadOnChange: true)
.Build();
Question
Is it possible to make ConfigurationBuilder use the embedded JSON file directly without creating a new temporary file as I did above? If yes, how to do so?