如何在Team Services中替换json文件的变量? [英] How to replace variables of json file in Team Services?

查看:74
本文介绍了如何在Team Services中替换json文件的变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我被一个角项目的释放变量替换卡住了.我有一个settings.json文件,我想替换一些变量:

Im stuck with a release variable substitution of an angular project. I have a settings.json file wich i would like to replace some variables:

{ 
    test : "variable to replace"
}

我试图在市场上找到一些自定义任务,但所有任务似乎仅适用于web.config的xml文件.

I tried to find some custom task on the marketplace but all of the tasks seems to work only with xml files for the web.config.

推荐答案

我使用了市场中的替换令牌" https://marketplace.visualstudio.com/items?itemName=qetza.replacetokens

I use the "Replace tokens" from the Marketplace https://marketplace.visualstudio.com/items?itemName=qetza.replacetokens

您可以在发布定义"中将所需的值定义为变量,然后添加替换令牌"任务,并为要替换值的存储库中的所有目标文本文件配置通配符路径(例如:**/*). json).被替换的令牌具有可配置的前缀和后缀(默认为'#{'和'}#').因此,如果您有一个名为 constr 的变量,则可以放入config.json

You define the desired values as variables in the Release Definition and then you add the Replace Tokens task and configure a wildcard path for all target text files in your repository where you want to replace values (for example: **/*.json). The token that gets replaced has configurable prefix and postfix (default are '#{' and '}#'). So if you have a variable named constr you can put in your config.json

{
   "connectionstring": "#{constr}#"
}

它将像这样部署文件

{
   "connectionstring": "server=localhost,user id=admin,password=secret"
}

这篇关于如何在Team Services中替换json文件的变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆