我试图使用以下方法在文件中查找和替换.
Function Find-Replace ($FileFullpath, $FindString, $ReplacementString) {
Get-Content $FileFullpath |
Foreach-Object {$_ -replace $FindString, $ReplacementString } |
Set-Content $FileFullpath
}
Find-Replace "c:\program files (x86)\MyProj\web.config" $OldServiceName $NewServiceName
Run Code Online (Sandbox Code Playgroud)
但我总是得到错误.
Set-Content:进程无法访问文件'c:\ program files(x86)\ MyProj\web.config',因为它正由另一个进程使用.
该文件不会在任何地方打开.我认为Get-content尚未发布该文件.
为什么会这样?如何在同一个文件中查找和替换没有问题?