What is the best way to upgrade XML node in MSBuild

I use Tigris community tasks to update various AppSettings keys using the XMLUpdate task.

Now, however, I want to add node to the system.net section to configure proxies.

I declared a property

<PropertyGroup>
    <proxy>&lt;defaultProxy&gt; &lt;proxy usesystemdefault="False" proxyaddress="http://IPADDRESS:PORT" /&gt; &lt;/defaultProxy&gt;</proxy>
  </PropertyGroup>

and the XMLUpdate task looks like

<XmlUpdate
 Prefix="n"
 Namespace="http://schemas.microsoft.com/.NetConfiguration/v2.0"
 XmlFileName="$(BuildDir)\Builds\_PublishedWebsites\Presentation\Web.config"
 XPath="/n:configuration/n:system.net"
 Value="$(proxy)"  />

this updates the web configuration, however it is updated directly from the property group, i.e. does not convert escape characters for angle brackets. Does anyone have any idea?

+5
source share
1 answer

You can use XmlMassUpdate instead of the XmlUpdate task.

<ProjectExtensions>
  <defaultProxy>
    <proxy usesystemdefault="False" proxyaddress="http://IPADDRESS:PORT"/>
  </defaultProxy>
</ProjectExtensions>

<Target Name="SubstituteFromWebConfig">
  <XmlMassUpdate 
    NamespaceDefinitions="msb=http://schemas.microsoft.com/developer/msbuild/2003;n=http://schemas.microsoft.com/.NetConfiguration/v2.0"
    ContentFile="$(BuildDir)\Builds\_PublishedWebsites\Presentation\Web.config" 
    ContentRoot="/n:configuration/n:system.net"
    SubstitutionsFile="$(MSBuildProjectFullPath)"
    SubstitutionsRoot="/msb:Project/msb:ProjectExtensions/msb:system.web" />
</Target> 

node, ContentRoot ContentFile, , SubstitutionsRoot SubstitutionsFile ( MSBuild).

MSBuild ProjectExtensions, XML , MSBuild. > .

( XmlMassUpdate, XmlRead node ProjectExtensions XmlUpdate.)

+7

All Articles