Skip to content

Commit

Permalink
Use config from current working dir (neo-project#1622)
Browse files Browse the repository at this point in the history
* Use config from current dir

* Search in multiple places
  • Loading branch information
shargon authored and Tommo-L committed Jun 22, 2020
1 parent e78861f commit c21ec37
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/neo/Utility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
using Microsoft.Extensions.Configuration;
using Neo.Plugins;
using System;
using System.IO;
using System.Reflection;

namespace Neo
{
Expand All @@ -26,8 +28,27 @@ public static IConfigurationRoot LoadConfig(string config)
{
var env = Environment.GetEnvironmentVariable("NEO_NETWORK");
var configFile = string.IsNullOrWhiteSpace(env) ? $"{config}.json" : $"{config}.{env}.json";

// Working directory
var file = Path.Combine(Environment.CurrentDirectory, configFile);
if (!File.Exists(file))
{
// EntryPoint folder
file = Path.Combine(Assembly.GetEntryAssembly().Location, configFile);
if (!File.Exists(file))
{
// neo.dll folder
file = Path.Combine(Assembly.GetExecutingAssembly().Location, configFile);
if (!File.Exists(file))
{
// default config
return new ConfigurationBuilder().Build();
}
}
}

return new ConfigurationBuilder()
.AddJsonFile(configFile, true)
.AddJsonFile(file, true)
.Build();
}

Expand Down

0 comments on commit c21ec37

Please sign in to comment.