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

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

问题描述

我坚持使用角度项目的发布变量替换.我有一个 settings.json 文件,我想替换一些变量:

I'm stuck with a release variable substitution of an angular project. I have a settings.json file which 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.

推荐答案

我使用 Marketplace 中的替换令牌"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天全站免登陆