-
Notifications
You must be signed in to change notification settings - Fork 203
AddJsonFile throws invalid directory name when optional is true #478
Comments
Related aspnet/FileSystem#199 |
We really need this to work when the directory is missing because in Antares we watch some config files that don't exist yet, not their parent folder is there. So the configuration (and the file watcher) should support watching a folder and files in folders that don't exist yet. It's required by the Antares integration work items. cc @glennc |
Looks like we can fix this for absolute paths by walking up the path and creating the physical file provider against that directory leaving the rest of the path for the file, i.e. Updating the code here: https://github.com/aspnet/Configuration/blob/dev/src/Microsoft.Extensions.Configuration.Ini/IniConfigurationExtensions.cs#L76
Sound reasonable? cc @divega |
I think that would work.. My only concern is perf if you end up watching the disk's root and there's a lot of file watching. Btw, that change is not just for ini files, right? |
var builder = new Microsoft.Extensions.Configuration.ConfigurationBuilder()
.SetBasePath(env.ContentRootPath)
.AddJsonFile(@"C:/myDirectory/mySub/appsettings.json", optional: true)
When adding a configuration file during app startup, the above code will throw an exception if the "C:/myDirectory/mySub/" directory does not exist. Since this is set as an optional file, the directory should not need to exist.
The text was updated successfully, but these errors were encountered: