XmlFile.SetAttribute fails

Aug 21, 2008 at 1:18 AM
Edited Aug 21, 2008 at 1:26 AM
I am trying to update a key/value pair in my web.config file, for which there exists the key. I have validated that the XPath expression is accurate, yet it cannot find the element. I am not using the optional Namespaces attribute, as I think a web.config is not under the constraint of a namespace (?).

Below is what I am doing, followed by error message. If you can provide insights as to what could be wrong, please advise.

<XmlFile.SetAttribute
Path="C:\Build\web.config"
XPath="/configuration/appSettings/add[@key='customErrorEmailAddress']"
Name="value"
Value="myVal"
IgnoreNoMatchFailure="false"
Force="true" />

Could not find resource string No matches found for XPath expression '/configuration/appSettings/add[@key='customErrorEmailAddress']'.
ErrorEvent detected.8/20/2008 5:11:55 PM - A task error has occured.
Message = No matches found for XPath expression '/configuration/appSettings/add[@key='customErrorEmailAddress']'.
Name = value
Value = myVal
IgnoreNoMatchFailure = False
Force = True
XPath = /configuration/appSettings/add[@key='customErrorEmailAddress']
Path = C:\Build\web.config
Namespaces = <null>
at Microsoft.Sdc.Tasks.XmlFile.SetAttribute.InternalExecute()
at Microsoft.Sdc.Tasks.TaskBase.Execute()

 

Developer
Aug 21, 2008 at 9:25 AM
I can't repro here. Below is my working sample:

    <Target Name="Default">

        <XmlFile.SetAttribute

        Path="C:\Demo\web.config"

        XPath="/configuration/appSettings/add[@key='customErrorEmailAddress']"

        Name="value"

        Value="myVal"

        IgnoreNoMatchFailure="false"

        Force="true" />

    </Target>


Web before

<?xml version="1.0"?>

<configuration>

  <appSettings>

    <add key="HttpTraceModule_RouteTraceSourceType" value="UIComponent" />

    <add key="customErrorEmailAddress" value="OLDVALUE" />

  </appSettings>

</configuration>

Web after

 

<?xml version="1.0"?>

<configuration>

  <appSettings>

    <add key="HttpTraceModule_RouteTraceSourceType" value="UIComponent" />

    <add key="customErrorEmailAddress" value="myVal" />

  </appSettings>

</configuration>