2017-04-05 56 views
2

我无法弄清楚如何使用Cake中的XmlPoke更改XML节点的内部文本值。我不断收到错误是Error: Expression must evaluate to a node-set.使用CakeBuild XMLPoke更改节点的内部文本值

我的XML看起来像这样

<?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> 

而且我build.cake看起来像这样

// 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 

回答

4

您还需要设置的命名空间。就像这样:

// 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" } 
     } 
    }); 

而且,你可能也想看看Magic Chunks

+0

谢谢!现在我不必去掉/ p:OutDir =我开始朝向的路径。 Magic Chunk看起来会非常有帮助。 – Stephen