Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using CakeBuild XMLPoke change inner text value of node

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
like image 954
Stephen Gilboy Avatar asked Mar 10 '23 10:03

Stephen Gilboy


1 Answers

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

like image 146
bjorkstromm Avatar answered Mar 17 '23 12:03

bjorkstromm