Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add updateApplicationSetting method #462

Merged
merged 1 commit into from
Jun 9, 2014
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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