55using System . IO ;
66using System . Linq ;
77using System . Security . Cryptography ;
8+ using System . Xml . Linq ;
89using System . Text ;
910using Paket . Bootstrapper . HelperProxies ;
1011
@@ -27,6 +28,7 @@ public static class CommandArgs
2728 public const string Run = "--run" ;
2829 public const string OutputDir = "--output-dir=" ;
2930 public const string AsTool = "--as-tool" ;
31+ public const string ConfigFile = "--config-file=" ;
3032 }
3133 public static class AppSettingKeys
3234 {
@@ -85,6 +87,15 @@ public static BootstrapperOptions ParseArgumentsAndConfigurations(IEnumerable<st
8587 FillTarget ( options . DownloadArguments , magicMode , fileSystem ) ;
8688 }
8789
90+ var configFileArg = commandArgs . SingleOrDefault ( x => x . StartsWith ( CommandArgs . ConfigFile ) ) ;
91+ if ( configFileArg != null )
92+ {
93+ commandArgs . Remove ( configFileArg ) ;
94+ var configFilePath = configFileArg . Substring ( CommandArgs . ConfigFile . Length ) ;
95+ var newSettings = ReadSettings ( configFilePath ) ;
96+ appSettings = newSettings ;
97+ }
98+
8899 // 1 - AppSettings
89100 FillOptionsFromAppSettings ( options , appSettings ) ;
90101
@@ -155,6 +166,43 @@ public static BootstrapperOptions ParseArgumentsAndConfigurations(IEnumerable<st
155166 return options ;
156167 }
157168
169+ private static NameValueCollection ReadSettings ( string configFilePath )
170+ {
171+ var doc = XDocument . Load ( configFilePath ) ;
172+
173+ var nv = new NameValueCollection ( ) ;
174+
175+ var appSettings = doc . Root . Element ( "appSettings" ) ;
176+ if ( appSettings == null )
177+ throw new Exception ( string . Format ( "appSettings element not found in file '{0}'" , configFilePath ) ) ;
178+
179+ var dic =
180+ appSettings
181+ . Elements ( "add" )
182+ . Select ( x => {
183+ var keyAttr = x . Attribute ( "key" ) ;
184+ var valueAttr = x . Attribute ( "value" ) ;
185+ if ( keyAttr == null || valueAttr == null )
186+ return new KeyValuePair < string , string > ( ) ; ;
187+
188+ string key = keyAttr . Value ;
189+ if ( key == null )
190+ return new KeyValuePair < string , string > ( ) ; ;
191+
192+ string value = valueAttr . Value ;
193+ return new KeyValuePair < string , string > ( key , value ) ;
194+ } )
195+ . Where ( kv => kv . Key != null )
196+ . ToArray ( ) ;
197+
198+ foreach ( var kv in dic )
199+ {
200+ nv . Add ( kv . Key , kv . Value ) ;
201+ }
202+
203+ return nv ;
204+ }
205+
158206 private static void FillOptionsFromAppSettings ( BootstrapperOptions options , NameValueCollection appSettings )
159207 {
160208 if ( appSettings . IsTrue ( AppSettingKeys . PreferNuget ) )
0 commit comments