我想用msdeploy和powershell替换远程计算机上托管iis服务的web.config中的connectionString。
脚本运行没有错误:
$iisPath = "$iisServicePath,computerName=$computerName,userName=$userName,password=$password"
& "C:\Program Files\IIS\Microsoft Web Deploy V3\msdeploy.exe" `
"-source=contentPath=$iisPath" `
'-verb=sync' `
'-verbose' `
'-allowUntrusted' `
"-dest=contentPath=$iisPath" `
'-setParam=kind=TextFile,match="configuration/connectionStrings/add[@name=MyEntities]/@connectionString",scope=web\.config$,value="$newConString"';
脚本的详细输出说:
Verbose: The synchronization completed in 1 pass(es).
Total changes: 0 (0 added, 0 deleted, 0 updated, 0 parameters changed, 0 bytes copied)
未替换connectionString Attribute的值。
我该怎么做?
更新
这是我现在收到的错误消息:
Verbose: Parameter entry 'MSDeploySetParameter-2080747909/1' could not be applied to 'MyWebSite/MyService\Web.config'. Deployment will continue with the original data. Details:
No matches were found for the search string '`"configuration/connectionStrings/add[@name=MyEntities]/@connectionString`' (type 'TextFile').
Verbose: Attribute 'size' equality changed to False when comparing filePath (MyWebSite/MyService\Web.config) to MyWebSite/MyService\Web.config because of rule Parameterizat
ion.
Verbose: Source filePath (MyWebSite/MyService\Web.config) does not match destination (MyWebSite/MyService\Web.config) differing in attributes (parameters). Update pending.
Verbose: Source filePath (MyWebSite/MyService\Web.config) replaced with changed attributes (size['3710','3707']) because of rule Parameterization.
Info: Updating file (MyWebSite/MyService\Web.config).
Verbose: The dependency check 'DependencyCheckInUse' found no issues.
Verbose: The synchronization completed in 2 pass(es).
Total changes: 1 (0 added, 0 deleted, 1 updated, 0 parameters changed, 3707 bytes copied)
使用此更改代码:
& "C:\Program Files\IIS\Microsoft Web Deploy V3\msdeploy.exe" `
"-source=contentPath=$iisPath" `
'-verb=sync' `
'-verbose' `
'-allowUntrusted' `
"-dest=contentPath=$iisPath" `
'-setParam=kind=TextFile,match=`"configuration/connectionStrings/add[@name=MyEntities]/@connectionString`",scope=web\.config$,value=`"$newConString`"';
答案 0 :(得分:0)
更改此处的最后一行,您使用单引号,它将被完全解释为类型(例如,它不会交换变量的值)
我用双引号替换了你的单引号,然后继续使用内引号。如果这不起作用,请告诉我!
-setParam=kind=TextFile,match=`"configuration/connectionStrings/add[@name=MyEntities]/@connectionString`",scope=web\.config$,value=`"$newConString`" ";