tug*_*erk 5 xml powershell build-script powershell-2.0
在我的构建脚本中,我有一个helper powershell函数,如下所示:
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)
}
Run Code Online (Sandbox Code Playgroud)
它工作得很好,除了当我尝试设置值时,它奇怪地编码了&符号.这是问题:
在我的连接字符串里面,我"有价值.这应该是完全有效的.但是,我的上述代码将此转换"为完全不合理的.你知道我能解决这个问题吗?
您是否先尝试decode连接字符串?这是样本:
[System.Reflection.Assembly]::LoadWithPartialName("System.web")
[System.Web.HttpUtility]::HtmlDecode(""")
Run Code Online (Sandbox Code Playgroud)