2017-04-05 40 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

相關問題