2009-08-13 2 views
10

MSBuildMSBuild Community Tasks (XMLUpdate 및 XMLMassUpdate 사용)을 사용하여 Web.config의 여러 섹션을 업데이트했습니다. 내가있는 경우 :MSBuild 스크립트에서 XML 속성을 어떻게 업데이트합니까?

<configuration> 
    <nlog throwExceptions="true" xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 
     <targets> 
      <target name="file" xsi:type="File" fileName="${logDirectory}\SomeLog.log" layout="${message}"/> 
     </targets> 
    </nlog> 
</configuration> 

와 내가 뭔가를 업데이트 할 수 아무것도 찾을 수없는 것으로보고하는 target

<XmlUpdate XmlFileName="$(BuildDir)\Builds\%(Configuration.Identity)\_PublishedWebsites\Presentation\Web.config" 
      XPath="//configuration/nlog/targets/target[@fileName]" 
      Value="${logDirectory}\SomeLog_%(Configuration.Identity).log" /> 

fileName를 교체하려고, 그래서 제 질문은 내가 파일 이름 속성을 얻을 수있는 방법이다 업데이트?


편집 : NLog 섹션은 자신의 네임 스페이스를 정의로이 네임 스페이스 충돌의 경우가 될 수 있을까?


UPDATE : 작동하지 않습니다 이름 공간을 선언 게시 된 대답.

답변

20

첫 번째 문제는 속성을 업데이트하기 위해 xpath가 잘못되었지만 "target"이라는 노드의 "fileName"속성이 아니라 "fileName"이라는 속성이있는 "대상"노드를 현재 찾고 있습니다.

당신이 원하는 XPath는 다음과 같습니다 네임 스페이스 문제, Preet Sangha has the correct answer for that에 관해서는, 당신은 네임 스페이스 접두사를 사용할 필요가 /구성/nlog/대상/대상/@ 파일 이름

,이 모든 하위에 적용해야합니다 왜냐하면 그들은 모두 그 네임 스페이스에 있기 때문입니다.

마지막 문장의 존재는 : 여기

<XmlUpdate 
    XmlFileName="web.config" 
    XPath="//configuration/x:nlog/x:targets/x:target/@fileName" 
    Value="%24{logDirectory}\SomeLog_%(Configuration.Identity).log" 
    Prefix="x" 
    Namespace="http://www.nlog-project.org/schemas/NLog.xsd" 
    /> 

:

<XmlUpdate 
    Prefix="n" 
    Namespace="http://www.nlog-project.org/schemas/NLog.xsd" 
    XmlFileName="output.xml" 
    XPath="//configuration/n:nlog/n:targets/n:target/@fileName" 
    Value="${logDirectory}\UpdateWorked.log" /> 
+0

이것은 매력처럼 작동했다 .... 매우 감사드립니다! – Dean

4

Here는 네임 스페이스

<XmlUpdate 
    Namespace="http://schemas.microsoft.com/.NetConfiguration/v2.0" 
    XmlFileName .... 

당신이 다른 속성을 업데이트 할 수 있습니다의 요구 사항을 나타냅니다?

+0

이것은 유용하지만 현재의 문제를 해결하지 못한다. 네임 스페이스를 선언했지만 올바르게 업데이트하지 않는 다른 XMLUpdate 작업이있다. – Dean

3

keeperofthesoul(난 당신이 그에게 BTW 현상금을 제공한다고 생각합니다)에 의해 주어진 답을 완료하려면 좀 봐 %24을 사용하여 특수 문자 $을 작성하십시오.

관련 문제