qt-creator - 选择Git时如何有条件地生成文件?
问题描述
为了使用 Qt Creator 加快我的工作流程,我创建了一个 JSON 格式的自定义项目向导,作为其中的一部分,我添加了一个摘要页面:
{
"trDisplayName": "Project Management",
"trShortTitle": "Summary",
"typeId": "Summary"
}
在文件生成器中,我将两个文件(即.gitattributes
和.gitignore
)复制到项目目录中:
{
"source": ".gitattributes",
"target": "%{TargetPath}/.gitattributes"
},
{
"source": ".gitignore",
"target": "%{TargetPath}/.gitignore"
}
像这样写的,文件总是被复制的,即使没有选择 Git 作为版本控制系统。我希望仅在需要时才复制文件。
摘要页面的文档说:
它将 VersionControl 设置为正在使用的版本控制系统的 ID
但没有添加有关VersionControl
变量及其值的更多信息。
如何达到预期的效果?
解决方案
我会建议你以下解决方案:
Wizard.Inspect
通过转到为命令分配键盘快捷键工具->选项->环境->键盘->快捷键
启动自定义向导并导航到摘要页面
按选定的快捷方式
这将打开一个窗口,其中列出了触发操作时向导中所有已定义的字段和变量。在那里你可以找到:
Key | Type | Value | Eval VersionControl | QString | G.Git | G.Git
有了这些信息,像这样更改文件生成器代码:
{ "source": ".gitattributes", "target": "%{TargetPath}/.gitattributes", "condition": "%{JS: '%{VersionControl}' === 'G.Git'}" }, { "source": ".gitignore", "target": "%{TargetPath}/.gitignore", "condition": "%{JS: '%{VersionControl}' === 'G.Git'}" }
推荐阅读
- graphql - 中继编译器语法错误:预期名称,找到“}”
- r - 聚集标准误和缺失值
- java - onErrorResume 和 onErrorReturn 的区别
- java - 如何在 Payara Docker 容器上安装 PostgreSQL?
- json - 如何从 json 中提取这些值
- html - 我已尽我所能,但我的网站无法在 iPhone 上运行或响应
- sql - 通过 ODBC 而不是 ADODB 访问 Excel VBA 数据库
- java - 使用 codelabs 构建我的第一个应用程序遇到了一些问题
- view - 如何在swiftui中访问其他视图结构中的视图结构
- python - 分析数据时如何避免重复表达?