相关疑难解决方法(0)

在powershell中保存XML文件需要完整的路径.为什么?

我正在使用powershell的XML功能来修改.config文件.除非我提供完整的路径名,否则调用XMLDocument.Save没有任何效果.

# Open the xml file
$config = [xml](get-content web.config)
#
# modify the XML
$config.SelectNodes("./configuration/connectionStrings/add[@name='LocalSqlServer']") | % { $connNode = $_ }
$connNode.connectionString = $connNode.connectionString -replace '^(.*)Server=[^;]+(.*)$', '$1Server=192.168.5.2$2'
#
#
# Now I save it again
#
# This doesn't save it!
$config.Save("web.config");
# However, this works
$config.Save("{0}\\web.config" -f (get-location));
Run Code Online (Sandbox Code Playgroud)

为什么$ config.Save("web.config")不起作用?

除了本地目录以外,我最终还是将它保存在其他地方吗?

xml powershell

48
推荐指数
2
解决办法
3万
查看次数

标签 统计

powershell ×1

xml ×1