Need some help with MSBuild.ExtensionPack.Xml.XmlFile

Sep 5, 2012 at 10:34 AM

Hi,

This is a question about usage of MSBuild.ExtensionPack.Xml.XmlFile. Its a stab in the dark expecting someone on here to be help with such a specific thing but I shall try anyway.

I am trying to update the Value of the SqlCmdvariable element whose Include attribute equals 'DeployTag' in the following XML:

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <IncludeCompositeObjects>True</IncludeCompositeObjects>
    <TargetDatabaseName>PM_STG</TargetDatabaseName>
    <DeployScriptFileName>PM_STG.sql</DeployScriptFileName>
    <TargetConnectionString>Data Source=.\SQL2012;Integrated Security=True;Pooling=False</TargetConnectionString>
    <ProfileVersionNumber>1</ProfileVersionNumber>
  </PropertyGroup>
  <ItemGroup>
    <SqlCmdVariable Include="DeployTag">
      <Value>UNKNOWN</Value>
    </SqlCmdVariable>
  </ItemGroup>
</Project>

In other words, I want to replace the value UNKNOWN with some value that I pass in. Here is my call to MsBuild.ExtensionPack.Xml.XmlFile:

<MSBuild.ExtensionPack.Xml.XmlFile TaskAction="UpdateElement" File="%(SSDTPublishFiles.Identity)" XPath="//SqlCmdVariable[@Include='DeployTag']/Value" InnerText="$(CCNetLabel)"/>

This isn't having any effect (i.e. it isn't changing the XML file). If I strip out the namespace from the original XML:

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0">
  <PropertyGroup>
    <IncludeCompositeObjects>True</IncludeCompositeObjects>
    <TargetDatabaseName>PM_STG</TargetDatabaseName>
    <DeployScriptFileName>PM_STG.sql</DeployScriptFileName>
    <TargetConnectionString>Data Source=.\SQL2012;Integrated Security=True;Pooling=False</TargetConnectionString>
    <ProfileVersionNumber>1</ProfileVersionNumber>
  </PropertyGroup>
  <ItemGroup>
    <SqlCmdVariable Include="DeployTag">
      <Value>UNKNOWN</Value>
    </SqlCmdVariable>
  </ItemGroup>
</Project>

then it works fine...thus proving that my XPath expression is correct.

Trouble is, that namespace WILL be in there. So....how can I change my call to MsBuild.ExtensionPack.Xml.XmlFile so that this works. I have tried:

<MSBuild.ExtensionPack.Xml.XmlFile TaskAction="UpdateElement" File="%(SSDTPublishFiles.Identity)" Namespaces="http://schemas.microsoft.com/developer/msbuild/2003" XPath="//SqlCmdVariable[@Include='DeployTag']/Value" InnerText="$(CCNetLabel)"/>
but that did not work (i.e. it didn't do change the XML file.).

 

Any advice would be much appreciated.

 

regards
Jamie 

Sep 5, 2012 at 10:54 AM

OK, did a bit more digging and came up with this:

  <ItemGroup>
    <Namespaces Include="myns">
      <Prefix>myns</Prefix>
      <Uri>http://schemas.microsoft.com/developer/msbuild/2003</Uri>
    </Namespaces>
  </ItemGroup>
<MSBuild.ExtensionPack.Xml.XmlFile TaskAction="UpdateElement" File="%(SSDTPublishFiles.Identity)" Namespaces="@(Namespaces)" XPath="//myns:SqlCmdVariable[@Include='DeployTag']/myns:Value" InnerText="$(CCNetLabel)"/>

which worked :)

Coordinator
Sep 5, 2012 at 11:08 AM

Cool, I was going to point you here - http://msbuildextensionpack.codeplex.com/discussions/271277

Mike

Nov 6, 2014 at 1:55 PM
how would you do it if you wanted to update the "DeployTag" from the below line?


<SqlCmdVariable Include="DeployTag">
Coordinator
Apr 25, 2015 at 11:26 AM
Marked as answer by mikeFourie on 4/25/2015 at 3:26 AM