diff --git a/src/Paket.Bootstrapper/ArgumentParser.cs b/src/Paket.Bootstrapper/ArgumentParser.cs index 202c1a8955..9e00b8d0d9 100644 --- a/src/Paket.Bootstrapper/ArgumentParser.cs +++ b/src/Paket.Bootstrapper/ArgumentParser.cs @@ -5,6 +5,7 @@ using System.IO; using System.Linq; using System.Security.Cryptography; +using System.Xml.Linq; using System.Text; using Paket.Bootstrapper.HelperProxies; @@ -27,6 +28,7 @@ public static class CommandArgs public const string Run = "--run"; public const string OutputDir = "--output-dir="; public const string AsTool = "--as-tool"; + public const string ConfigFile = "--config-file="; } public static class AppSettingKeys { @@ -85,6 +87,15 @@ public static BootstrapperOptions ParseArgumentsAndConfigurations(IEnumerable x.StartsWith(CommandArgs.ConfigFile)); + if (configFileArg != null) + { + commandArgs.Remove(configFileArg); + var configFilePath = configFileArg.Substring(CommandArgs.ConfigFile.Length); + var newSettings = ReadSettings(configFilePath); + appSettings = newSettings; + } + // 1 - AppSettings FillOptionsFromAppSettings(options, appSettings); @@ -155,6 +166,43 @@ public static BootstrapperOptions ParseArgumentsAndConfigurations(IEnumerable { + var keyAttr = x.Attribute("key"); + var valueAttr = x.Attribute("value"); + if (keyAttr == null || valueAttr == null) + return new KeyValuePair(); ; + + string key = keyAttr.Value; + if (key == null) + return new KeyValuePair(); ; + + string value = valueAttr.Value; + return new KeyValuePair(key, value); + }) + .Where(kv => kv.Key != null) + .ToArray(); + + foreach (var kv in dic) + { + nv.Add(kv.Key, kv.Value); + } + + return nv; + } + private static void FillOptionsFromAppSettings(BootstrapperOptions options, NameValueCollection appSettings) { if (appSettings.IsTrue(AppSettingKeys.PreferNuget)) diff --git a/src/Paket.Bootstrapper/Paket.Bootstrapper.csproj b/src/Paket.Bootstrapper/Paket.Bootstrapper.csproj index 92676a9110..8c52a260c5 100644 --- a/src/Paket.Bootstrapper/Paket.Bootstrapper.csproj +++ b/src/Paket.Bootstrapper/Paket.Bootstrapper.csproj @@ -52,6 +52,7 @@ + diff --git a/src/Paket.Bootstrapper/Program.cs b/src/Paket.Bootstrapper/Program.cs index 410408aa1c..47072af42e 100644 --- a/src/Paket.Bootstrapper/Program.cs +++ b/src/Paket.Bootstrapper/Program.cs @@ -34,8 +34,23 @@ static void Main(string[] args) var fileProxy = new FileSystemProxy(); - var appSettings = - ConfigurationManager.AppSettings; + var appSettings = ConfigurationManager.AppSettings; + + var appConfigInWorkingDir = Path.Combine(Environment.CurrentDirectory, "paket.bootstrapper.exe.config"); + if (File.Exists(appConfigInWorkingDir)) + { + var exeInWorkingDir = Path.Combine(Environment.CurrentDirectory, "paket.bootstrapper.exe"); + var exeConf = ConfigurationManager.OpenExeConfiguration(null); + if (exeConf != null) + { + var nv = new System.Collections.Specialized.NameValueCollection(); + foreach (KeyValueConfigurationElement kv in exeConf.AppSettings.Settings) + { + nv.Add(kv.Key, kv.Value); + } + appSettings = nv; + } + } var optionsBeforeDependenciesFile = ArgumentParser.ParseArgumentsAndConfigurations(args, appSettings, Environment.GetEnvironmentVariables(), fileProxy, Enumerable.Empty());