Question:
In my build script, I have a helper powershell function as below:
1 2 3 4 5 6 7 8 9 10 |
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?
Answer:
Have you try to decode
your connection string first? Here is sample:
1 2 3 |
[System.Reflection.Assembly]::LoadWithPartialName("System.web") [System.Web.HttpUtility]::HtmlDecode(""") |