Skip to content

Commit

Permalink
Merge pull request #462 from ssteward54/patch-1
Browse files Browse the repository at this point in the history
Add updateApplicationSetting method
  • Loading branch information
forki committed Jun 9, 2014
2 parents dd42061 + abc029e commit 86185e1
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 86185e1

Please sign in to comment.