web.config의 appSettings 요소에 대한 configSource를 업데이트하여 다른 환경에 대한 web.config를 업데이트하는 방법을 찾으려고합니다.매개 변수를 전달하여 Powershell을 사용하여 web.config의 XML 요소의 configSource를 업데이트하십시오.
내가 어떻게하는지 알고있는 방법입니다.
$xml.get_DocumentElement().appSettings.configSource = $replaced_test
문제
내가 내가 내가 변경하려면 스크립트 및 업데이트에 서로 다른 노드에 전달할 수있는 하나의 기본 스크립트를 원하지만 내가 그것을 할 방법을 잘 모르겠습니다이다.예를 들어, 나는이 충분히 분명 희망이
changeWebConfig.ps1 nodeToChange newValueofNode
같은 PowerShell 스크립트를 호출 할 수 있어야합니다.
이것은 내가 지금 가지고있는 코드입니다.
$webConfigPath = "C:\web.config"
# Get the content of the config file and cast it to XML
$xml = [xml](get-content $webConfigPath)
#this was the trick I had been looking for
$root = $xml.get_DocumentElement()."system.serviceModel".client.configSource = $replace
# Save it
$xml.Save($webConfigPath)
내가
<configuration>
에
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
이에서를 변경 한 구성 노드
을했다 가졌다 문제 어떻게 확실하지 않다 구성을 가진 노드를 찾으려면 이온 노드는 아직 원래 상태입니다.하지만 점점 가까워지고 있습니다.
function Set-ConfigAppSetting
([string]$PathToConfig=$(throw 'Configuration file is required'),
[string]$Key = $(throw 'No Key Specified'),
[string]$Value = $(throw 'No Value Specified'))
{
if (Test-Path $PathToConfig)
{
$x = [xml] (type $PathToConfig)
$node = $x.SelectSingleNode("//client[@configSource]")
$node.configSource = $Value
$x.Save($PathToConfig)
}
}
set-configappsetting "c:\web.config" CurrentTaxYear ".\private$\dinnernoworders" -confirm
참고하면 get_DocumentElement를 사용할 필요가 없습니다) (: 여기
노드가 뭐죠 볼 수있는 방법입니다. $ xml.SelectSingleNode ("...")는 SelectSingleNode가 XmlDocument에서도 사용 가능하며,이 경우 $ xml이 사용 가능합니다. –