문제

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 &quot 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(""")

다른 팁

You are sticking $value in the middle of a string literal, so it is behaving as though you had typed: $setting.connectionString = ""something"". This is not an XML operation, it is a .NET string assignment, so anything on the right hand side of the equal needs to be literally what you want in the connection string, not the escaped XML attribute representation. So either pass it in unescaped, or unescape it before the assignment.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top