In my build script, I have a helper powershell function as below:
function set-connectionstring {
param($path, $name, $value)
$settings = [xml](get-content $path)
$setting = $settings.configuration.connectionStrings.add | where { $_.name -eq $name }
$setting.connectionString = "$value"
$setting.providerName = "System.Data.SqlClient"
$resolvedPath = resolve-path($path)
$settings.save($resolvedPath)
}
It works great except that when I try to set the value, it encodes ampersands weirdly. Here is the issue:
Inside my connection string I have "
value. This should be perfectly valid. However, my above code transforms this into "
which is totally unreasonable. Do you have any idea I can solve this problem?
Have you try to decode
your connection string first? Here is sample:
[System.Reflection.Assembly]::LoadWithPartialName("System.web")
[System.Web.HttpUtility]::HtmlDecode(""")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With