Skip to content
This repository has been archived by the owner on Dec 18, 2018. It is now read-only.

Make SetBasePath() optional #295

Closed
divega opened this issue Sep 23, 2015 · 0 comments
Closed

Make SetBasePath() optional #295

divega opened this issue Sep 23, 2015 · 0 comments
Assignees
Milestone

Comments

@divega
Copy link

divega commented Sep 23, 2015

Initially it was possible to get going with Configuration with code like this:

var builder = new ConfigurationBuilder()
 .AddIniFile("config.ini")
 .AddJsonFile("config.json");

Currently it is necessary to provide the base path externally. With a PR that is currently in the works, it looks like this:

var builder = new ConfigurationBuilder()
 .SetBasePath(basePath) 
 .AddIniFile("config.ini")
 .AddJsonFile("config.json");

We can go back to make it optional. You won't need to call SetBase() by default, but it might still be useful to be able to do so for test scenarios or any time you want to artificially set it to something different from the base path of the application.

The logic will be in the new Microsoft.Framework.Configuration.FileExtensions package in the ResolveConfigurationFilePath() method, which will default to a base path for the application if not specified.

This will require cross compilation because there is no uniform way to get the right path across all platforms supported by Configuration. Here is the summary of how that will work based on @davidfowl's analysis:
• .NET Core (Contract based), this includes dnxcore50 - AppContext.BaseDirectory (this also works on .net 4.6 but we’ll ignore that)
• .NET 4.x - AppDomain.CurrentDomain.BaseDirectory__
• DNX4.x based - (string)AppDomain.CurrentDomain.GetData(“APP_CONTEXT_BASE_DIRECTORY”)

Note form @davidfowl:

Instead of cross compiling for DNX specifically you can make the .NET 4.x version check (string)AppDomain.CurrentDomain.GetData("APP_CONTEXT_BASE_DIRECTORY") before looking at the base directory.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants