Skip to content

Commit

Permalink
Add updateApplicationSetting method
Browse files Browse the repository at this point in the history
Added an updateApplicationSetting method that will allow you to update the newer applicationSettings in addition to just appSettings.
  • Loading branch information
ssteward54 committed Jun 6, 2014
1 parent 9d55328 commit abc029e
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/app/FakeLib/ConfigurationHelper.fs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,24 @@ let updateConfigSetting fileName xpath attribute value =
let updateAppSetting key value fileName =
updateConfigSetting fileName ("//appSettings/add[@key='" + key + "']") "value" value

/// Reads a config file from the given file name, replaces the Application Setting (as opposed to AppSetting) value and writes it back.
/// ## Parameters
/// - `settingName` - The ApplicationSetting name for which the value should be replaced.
/// - `value` - The new ApplicationSetting value.
/// - `fileName` - The file name of the config file.
///
/// ## Sample
///
/// updateApplicationSetting "DatabaseName" targetDatabase (navServicePath @@ "CustomSettings.config")
let updateApplicationSetting (fileName : string) settingName value =
let doc = new XmlDocument()
let xpath = "/configuration/applicationSettings//setting[@name=\"" + settingName + "\"]/value"
doc.Load fileName
let node = doc.SelectSingleNode xpath
if node = null then failwithf "XML node '%s' not found" xpath
node.InnerText <- value
doc.Save fileName

/// Reads a config file from the given file name, replaces the connection string value and writes it back.
/// ## Parameters
/// - `connectionStringKey` - The connection string key name for which the value should be replaced.
Expand All @@ -78,4 +96,4 @@ let applyXslOnConfig (xsl:string) fileName =
xslDoc.Load xsl
readConfig fileName
|> Fake.XMLHelper.XslTransform xslDoc
|> writeConfig fileName
|> writeConfig fileName

0 comments on commit abc029e

Please sign in to comment.