2017-09-05 63 views
-1

我有一个json文件和一个xml文件。在xml文件中,我有一个元素,名称在发布者名称的根目录下,并在json文件中读取该元素的值。如何实现这种情况。在JSON中读取XML值

JSON文件

{ 
    "manifestVersion": 1, 
    "id": "build-my-json", 
    "version": "0.6.4", 
    "name": "Build Extension", 
    "description": "Integrate", 
    "publisher": "name" 
    } 

XML文件

<?xml version="1.0" encoding="UTF-8"?> 
</publishername> 
    <name>Nitin</name> 
</publishername> 

基本上我想使出版商的名称为动态扩展TFS。

回答

0

我假设你是发布通过创建扩展,你可以添加PowerShell的任务来更新每个XML文件发布:

PowerShell脚本:

param(
    [string]$xmlfile, 
    [string]$jsonfile 
) 
$xml = [xml](Get-Content $xmlfile) 
$publisher=$xml.publishername.name 
Write-Output $publisher 
$a = Get-Content $jsonfile -raw | ConvertFrom-Json 
$a.publisher=$publisher 
$a | ConvertTo-Json | set-content $jsonfile 

参数:-xmlfile [xml file] -jsonfile [json file]

更新:

它不支持在扩展发布时更新发布者。我建议你通过构建/发布发布扩展。

+0

谢谢@ strain-MSFT我没有发布任何扩展构建我发布我的VSTS扩展,我只是想通过xml文件运行时更改我的发布者名称 –

+0

@NitinParashar在发布运行时? –

+0

@ strain-MSFT yes –