使用powershell脚本替换app.config中的文本

时间:2012-09-12 11:42:04

标签: teamcity powershell-v2.0 replace

我正在尝试使用简单的替换脚本来替换app.cofig文件中的文本。但它只是处理并且什么都不做:

$old = 'Z:\gene'
$new = 'z:\gene\scripts'
Get-ChildItem z:\gene\scripts\Test\App.config -Recurse | Where {$_ -IS [IO.FileInfo]} |
% {
(Get-Content $_.FullName) -replace $old,$new | Set-Content $_.FullName
Write-Host "Processed: " + $_.FullName
}

任何想法我做错了什么。因为相同的脚本适用于.txt文件 感谢

1 个答案:

答案 0 :(得分:1)

App.config是xml格式的,但它也是一个文本文件,它的工作方式应该相同。我的猜测是,你有一个不同的价值观,你的工作,他们没有打。如果您将文件重命名为app.txt它是否有效?如果从nant脚本运行,您可能还会考虑使用nant xmlpoke。

相关问题