From abc029ecf9d6755a68d2413777c3e65550842dd3 Mon Sep 17 00:00:00 2001 From: ssteward54 Date: Fri, 6 Jun 2014 15:53:04 -0500 Subject: [PATCH] Add updateApplicationSetting method Added an updateApplicationSetting method that will allow you to update the newer applicationSettings in addition to just appSettings. --- src/app/FakeLib/ConfigurationHelper.fs | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/app/FakeLib/ConfigurationHelper.fs b/src/app/FakeLib/ConfigurationHelper.fs index 841b9b2ffe9..e6f331facb2 100644 --- a/src/app/FakeLib/ConfigurationHelper.fs +++ b/src/app/FakeLib/ConfigurationHelper.fs @@ -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. @@ -78,4 +96,4 @@ let applyXslOnConfig (xsl:string) fileName = xslDoc.Load xsl readConfig fileName |> Fake.XMLHelper.XslTransform xslDoc - |> writeConfig fileName \ No newline at end of file + |> writeConfig fileName