4

I'm having trouble figuring out how I can change the inner text value of an XML node using XmlPoke in Cake. The error I keep getting is Error: Expression must evaluate to a node-set.

My XML looks like this

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <WebPublishMethod>FileSystem</WebPublishMethod>
    <LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
    <LastUsedPlatform>Any CPU</LastUsedPlatform>
    <SiteUrlToLaunchAfterPublish />
    <LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>
    <ExcludeApp_Data>False</ExcludeApp_Data>
    <publishUrl>This value must be set to your local path</publishUrl>
    <DeleteExistingFiles>False</DeleteExistingFiles>
  </PropertyGroup>
</Project>

And my build.cake looks like this

// Update the publish path in the pubxml
XmlPoke(publishProfile, "/Project/PropertyGroup/publishUrl/", buildPaths.PublishDirectory);

// The publishProfile is just the location of the XML file
// The buildPaths.PublishDirectory is the value I'm trying to set the inner text to
devlead
  • 4,935
  • 15
  • 36
Stephen Gilboy
  • 5,572
  • 2
  • 30
  • 36

1 Answers1

7

You'll also need to set the namespace. Like this:

// Update the publish path in the pubxml
XmlPoke(publishProfile,
    "/ns:Project/ns:PropertyGroup/ns:publishUrl",
    buildPaths.PublishDirectory,
    new XmlPokeSettings {
        Namespaces = new Dictionary<string, string> {
            { "ns", "http://schemas.microsoft.com/developer/msbuild/2003" }
        }
    });

Also, You might also want to check out Magic Chunks

bjorkstromm
  • 423
  • 2
  • 5
  • Thanks! Now I don't have to go down the /p:OutDir= path I was starting to head towards. And Magic Chunks looks like it'll be extremely helpful. – Stephen Gilboy Apr 05 '17 at 17:27