Answer: Based on putus answer, I figured out the following configuration to build and debug with one click
At first you need to add a task to build the binary with the respective tags.
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "0.1.0",
"command": "bash",
"isShellCommand": true,
"args": [""],
"showOutput": "always",
"tasks": [
{
"taskName": "buildBinWithTag",
"command": "go",
"args": ["build", "-o", "BinaryName", "-tags", "THISISATAG"],
"isShellCommand": true
}
]
}
This task should be executed before the debugger launches.
{
"version": "0.2.0",
"configurations": [
{
"name": "DebugBinWithTag", //added config
"type": "go",
"request": "launch",
"mode": "exec",
"remotePath": "",
"port": 2345,
"host": "127.0.0.1",
"program": "${workspaceRoot}/BinaryName",
"env": {},
"args": [],
"showLog": true,
"preLaunchTask": "buildBinWithTag"
}
]
}
Original question:I'm using build tags for compiling different versions of a Go program and I compile it with "go build -tags THISISAFLAG"
//+build THISISAFLAG
package main
This works perfectly. But is there a way to tell the debugger to use these flags. I've tried to use a launch configuration like the following, but it didn't work.
{
"version": "0.2.0",
"configurations": [
{
"name": "Launch",
"type": "go",
"request": "launch",
"mode": "debug",
"remotePath": "",
"port": 2345,
"host": "127.0.0.1",
"program": "${fileDirname}",
"env": {},
"args": ["-flags THISISAFLAG"],
"showLog": true
}
]
}