我已经编写了一些嵌入式代码(使用VS-Code作为我的IDE),可以将其部署到许多不同的设备上。
代码中包含文件config.h
,该文件定义了一个唯一的device_id
,需要为每个设备进行更改。
我有一个文件unique_ids.csv
,其中包含我需要使用的所有唯一ID。
VS-Code可以自动构建我的项目并创建一个名为project_name.bin
的文件。
如何设置一个脚本,该脚本自动从我的CSV文件中获取唯一ID,并为每个文件构建一个特定的device_id.bin
文件?
我怀疑这可能需要以某种方式利用Visual Studio任务。这是我当前的tasks.json
:
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "0.1.0",
"name": "make",
"isShellCommand": true,
"showOutput": "always",
"problemMatcher": {
"owner": "cpp",
"fileLocation": ["relative", "${workspaceRoot}/mbed-os"],
"pattern": {
"regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
"file": 1,
"line": 2,
"column": 3,
"severity": 4,
"message": 5
}
},
"args": ["-j"],
"linux": {
"command": "make"
},
"osx": {
"command": "make"
},
"windows": {
"command": "make.exe"
}
}
答案 0 :(得分:1)
想到另一种方法,我可能不会直接回答。
如果将csv用于发布而不是用于调试,为什么要在VS中构建发布? 我宁愿在VS内构建调试,并使用带有批处理脚本的命令行构建不同的发行版。
类似于此批伪代码
set id_list=unique_ids.csv
set id=
for %%a in (%id_list%) do (
set "id=%%~na"
replace in config.h device_id by device_%id%
make your_project
)