2

Im using the MSBuild task XmlUpdate to update my log4net file when deploying and it works like charm :). However today I discovered a BIG problem.

Problem: If I by accident specify the wrong Xpath, the script do not fail.

MSBuild Task config with error:

<Target Name="UpdateLog4NetConfig" DependsOnTargets="UpdateAppConfig">

  <XmlUpdate XmlFileName="$(ReleasePath)\log4net.config"
             Xpath="//log4net/root/ERRORNODE/@value"
             Value="WARN"
             ContinueOnError="false"/>
</Target>

When I run this I get:

[XmlUpdate] Updating Xml Document "D:\TeamCity Agents\...\output\log4net.config".
[XmlUpdate]   0 node(s) selected for update.
[XmlUpdate] XmlUpdate Wrote: "WARN".

But the build continues with the next tasks!

Question: How do I ensure that when an XmlUpdate "fails" , it actually stops the entire script with a big FAILED message?

(I know an XPath not actually "fails", but one should be able to tell if any changes where applied i think)

Kind regards

Christian Mikkelsen
  • 1,661
  • 2
  • 19
  • 44
  • I was about to suggest using XmlPoke instead but it also doesn't offer any task output which would allow to verify it actually made any replacements. Did you already check if `XmlUpdate` provides any Output TaskParameter you could check? – Filburt Aug 25 '11 at 14:45
  • No i havent. Actually I have never used the Output TaskParameter :/. I'm googling away :) – Christian Mikkelsen Aug 25 '11 at 15:05
  • 1
    Used The Force And Read The Source: `XmlUpdate` doesn't provide any property marked with `[Output]` and works pretty much the same as `XmlPoke`. Looks like you'll have to extend `XmlUpdate` yourself. – Filburt Aug 25 '11 at 15:31
  • I have now yielded the Force with great success and created my own XmlConfigUpdate Task which can fail and verify the amount of nodes affected. All in pour and lovely TDD style ;). What a nice, evening project :). Thx for the hint. – Christian Mikkelsen Aug 25 '11 at 21:57

0 Answers0