XmlFile

Mar 22, 2012 at 10:39 PM

Hi,

I want to update an the following XML but I'm having some trouble doing it.

<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">

<appSettings>

<add key="workFlow" value="C:\workflow"/>

</appSettings>

</configuration>

Here's is my task definition

<XmlFile 

  TaskAction="UpdateAttribute"

File="web.config"

  XPath="/configuration[@xmlns='http://schemas.microsoft.com/.NetConfiguration/v2.0']/appSettings/add[@key='workflow']" 

  Key="value" 

  Value="$(WorkflowConfigPath)"/>

 

The above task does not work, but the following works:

 

<configuration>

<appSettings>

<add key="workFlow" value="C:\workflow"/>

</appSettings>

</configuration>

-----------------------------------------------------------------------

<XmlFile 

TaskAction="UpdateAttribute"

File="web.config"

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

Key="value" 

Value="$(WorkflowConfigPath)"/>

 

Is there a way to get the first scenario to work?  If so, how?  I have other XML elements that has an xmlns attribute that I want to update, for instance hibernate configurations.

 

Thanks.

 

 

Coordinator
Mar 22, 2012 at 11:37 PM

Hi

You need to specify the namespace. You also have a case issue with your attribute filter value. It's a capital F in workFlow.

 

<Project ToolsVersion="4.0" DefaultTargets="DefaultWithNameSpace" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <Import Project="$(MSBuildExtensionsPath)\ExtensionPack\MSBuild.ExtensionPack.tasks"/>
    <!-- Sample XML
        <configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
  <appSettings>
    <add key="workFlow" value="XYZ" />
  </appSettings>
</configuration>
    -->
    <PropertyGroup>
        <WorkflowConfigPath>Mikes</WorkflowConfigPath>
    </PropertyGroup>
    <ItemGroup>
        <Namespaces Include="Mynamespace">
            <Prefix>x</Prefix>
            <Uri>http://schemas.microsoft.com/.NetConfiguration/v2.0</Uri>
        </Namespaces>
    </ItemGroup>
    <Target Name="DefaultWithNameSpace">
        <MSBuild.ExtensionPack.Xml.XmlFile Namespaces="@(Namespaces)"
                                            TaskAction="UpdateAttribute"
                                            File="temp.xml"
                                            XPath="/x:configuration/x:appSettings/x:add[@key='workFlow']"
                                            Key="value"
                                            Value="$(WorkflowConfigPath)"/>
    </Target>
</Project>

 

Mike

Mar 23, 2012 at 4:20 PM

Thanks! Mike