首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将web.config中的连接字符串替换为msdeploy

问将web.config中的连接字符串替换为msdeploy
EN

Stack Overflow用户
提问于 2016-03-30 22:34:29
回答 1查看 972关注 0票数 1

我想用msdeploy和powershell替换远程计算机上托管的iis服务的web.config中的connectionString。

该脚本运行时没有错误:

代码语言:javascript
复制
 $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"';

该脚本的详细输出为:

代码语言:javascript
复制
Verbose: The synchronization completed in 1 pass(es).
Total changes: 0 (0 added, 0 deleted, 0 updated, 0 parameters changed, 0 bytes copied)

未替换connectionString属性的值。

我该怎么做呢?

更新

这就是我现在得到的错误信息:

代码语言:javascript
复制
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)

使用此更改后的代码:

代码语言:javascript
复制
 & "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`"';
EN

回答 1

Stack Overflow用户

发布于 2016-03-30 22:53:57

更改这里的最后一行,您使用的是单引号,它将被完全解释为类型化(例如,它不会将值交换为变量)

我已经把你的单引号换成了双引号,并且把里面的引号也去掉了。如果这不起作用,让我知道!

代码语言:javascript
复制
-setParam=kind=TextFile,match=`"configuration/connectionStrings/add[@name=MyEntities]/@connectionString`",scope=web\.config$,value=`"$newConString`" ";
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36312023

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档