【发布时间】:2016-04-04 22:04:45
【问题描述】:
我有一个带有实体框架连接字符串的 web.config。
这是一个这样的字符串的样本:
<add name="MyEntities" connectionString="metadata=res://*/GeneratedModel.MyModel.csdl|res://*/GeneratedModel.MyModel.ssdl|res://*/GeneratedModel.MyModel.msl;provider=System.Data.SqlClient;provider connection string="data source=.\SQLEXPRESS;initial catalog=CRAP;persist security info=True;user id=MyUser;password=password;multipleactiveresultsets=True;application name=EntityFramework"" providerName="System.Data.EntityClient" />
我想用新名称“TEST”替换初始目录又名数据库名称“CRAP”
该代码应该像以前使用另一个 msdeploy.exe 命令一样工作。
我只需要重新构造 $msd 变量...
$newActiveTargetDbName = 'TEST';
$msd = "C:\Program Files\IIS\Microsoft Web Deploy V3\msdeploy.exe"
$iisPath = "MyWebSite/MyService,wmsvc='MyMachine:MyPort/msdeploy.axd',userName='username',password='password'"
& $msd -verb=sync -allowUntrusted -dest=contentPath="$iisPath" -source=contentPath="$iisPath" -setParam=kind="TextFile,match=""(MyEntities.*?catalog=).*?(;)"",scope=web.config$,value=`$1$newActiveTargetDbName`$2"
当我运行上面的语句时,我在 web.config 中得到了这个连接字符串:
<add name="$1TEST$2persist security info=True;user id=MyUser;password=password;multipleactiveresultsets=True;application name=EntityFramework"" providerName="System.Data.EntityClient" />
在我看来,我需要一些单引号/双引号等...但实际上我尝试了所有类型的组合,这让我发疯了。
我该如何解决这个问题?
更新
这是 msdeploy 语句的语法,在我更改之前它是如何工作的!
$iisServicePath = 'MyWebsite/MyService';
$iisPath = "$iisServicePath,computerName=%TargetComputerName%,userName=%NTUserName%,password=%NTUserPassword%"
& "C:\Program Files\IIS\Microsoft Web Deploy V3\msdeploy.exe" `
"-source=contentPath=$iisPath" `
'-verb=sync' `
'-verbose' `
'-allowUntrusted' `
"-dest=contentPath=$iisPath" `
"-setParam=kind=TextFile,match=""(MyEntities.*?catalog=).*?(;)"",scope=web.config$,value=`$1$newActiveTargetDbName`$2";
【问题讨论】:
标签: powershell msdeploy