XmlMassUpdate Class
From MSBuild
Performs multiple updates on an XML file
Namespace: MSBuild.Community.Tasks.Xml
Assembly: MSBuild.Community.Tasks (in MSBuild.Community.Tasks.dll)
Syntax
Example
These examples will demonstrate how to make multiple updates to a XML file named web.config. It looks like:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="ItemsPerPage" value="10" />
<add key="EnableCaching" value="true" />
<add key="DefaultServer" value="TIGRIS" />
</appSettings>
<system.web>
<compilation defaultLanguage="c#" debug="true" />
<customErrors mode="Off" />
<trace enabled="true" requestLimit="10" pageOutput="true" />
<globalization requestEncoding="utf-8" responseEncoding="utf-8" />
</system.web>
</configuration> | |
<XmlMassUpdate ContentFile="web.config" SubstitutionsFile="changes.xml" ContentRoot="/configuration/system.web" SubstitutionsRoot="/system.web" /> | |
<system.web>
<compilation debug="false" />
<customErrors mode="RemoteOnly" defaultRedirect="Error.htm">
<error statusCode="401" redirect="AccessDenied.aspx" />
</customErrors>
<trace enabled="false" />
</system.web> | |
<ProjectExtensions>
<system.web>
<compilation debug="false" />
<trace enabled="false" />
</system.web>
</ProjectExtensions>
<Target Name="SubstituteFromProj">
<XmlMassUpdate ContentFile="web.config" ContentRoot="/configuration/system.web"
NamespaceDefinitions="msb=http://schemas.microsoft.com/developer/msbuild/2003"
SubstitutionsFile="$(MSBuildProjectFullPath)"
SubstitutionsRoot="/msb:Project/msb:ProjectExtensions/msb:system.web" />
</Target> | |
<XmlMassUpdate ContentFile="web.config" SubstitutionsFile="changes.xml" MergedFile="web.config.keyed.xml" /> | |
<configuration xmlns:xmu="urn:msbuildcommunitytasks-xmlmassupdate">
<appSettings>
<add xmu:key="key" key="EnableCaching" value="false" />
<add xmu:key="key" key="DefaultSort" value="LastName" />
</appSettings>
</configuration> | |
<configuration xmlns:xmu="urn:msbuildcommunitytasks-xmlmassupdate">
<appSettings>
<add xmu:key="key" key="ItemsPerPage" xmu:action="remove" />
<trace xmu:action="remove" />
</appSettings>
</configuration> | |
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.web>
<compilation defaultLanguage="c#" debug="true" />
<customErrors mode="Off" />
<trace enabled="true" requestLimit="10" pageOutput="true" />
<globalization requestEncoding="utf-8" responseEncoding="utf-8" />
</system.web>
<substitutions>
<test>
<system.web>
<compilation debug="false" />
<trace enabled="true" />
</system.web>
</test>
<prod>
<system.web>
<compilation debug="false" />
<trace enabled="false" />
</system.web>
</prod>
</substitutions>
</configuration> | |
<XmlMassUpdate ContentFile="web.config" ContentRoot="/configuration" SubstitutionsRoot="/configuration/substitutions/$(TargetEnvironment)" /> | |
msbuild build.proj /p:TargetEnvironment=prod | |
Remarks
XmlMassUpdate allows to to specify multiple changes to make to an XML file (the
Any element within the
Any attribute declared within the and . The attribute allows you to define an attribute to use as the identifying attribute when you only want to update a single element, and multiple elements with the same name exist. You can also use the attribute to specify that an element should be deleted instead of updated.
Inheritance Hierarchy
Thread Safety
See Also
Documentation version 1.0.0.0.