與這裏quick'n髒腳本玩弄....
如果您確信只有一個在每個ConnectionString的元素文件,您可以用xmlpeek
和xmlpoke
組合實現這一點。修改字符串更容易一些C#完成的,因此使用腳本任務做一個正則表達式搜索和替換:
<script language="C#" prefix="custom" >
<code>
<![CDATA[
[Function("fix")]
public static string Fix(string input) {
return Regex.Replace(input, @"localhost\\\w+", "localhost");
}
]]>
</code>
</script>
<!-- Get the existing connection string -->
<xmlpeek
file="config01/app.config"
xpath="/configuration/connectionStrings/add[@contains(@connectionString,'localhost\')]/@connectionString"
property="connectionstring">
</xmlpeek>
<!-- Write back the modified connection string -->
<xmlpoke
file="config01/app.config"
xpath="/configuration/connectionStrings/add[@contains(@connectionString,'localhost\')]/@connectionString"
value="${custom::fix(connectionstring)}">
</xmlpoke>
感謝彼得 - 偉大的解決方案! – Remotec 2010-05-10 10:31:19
這真的很有幫助。 – 2014-09-24 00:50:36