'Is there a way to use build variables in launchSettings.json?
I am invoking NUnit console runner manually like this:
"MyRunConfig": {
"commandName": "Executable",
"executablePath": "nunit3-console.exe",
"commandLineArgs": "MyProject\\bin\\Debug\\MyProject.dll"
}
Problem is, I have to make a separate run configuration for Release build, as the output location is different. How do I do that? Can I somehow use TargetPath build property?
Solution 1:[1]
I'm using VS 2019 16.10.4, and I use the $(OutDir) and $(ConfigurationName) macros in my launchSettings.json. So your config could look like:
"MyRunConfig": {
"commandName": "Executable",
"executablePath": "nunit3-console.exe",
"commandLineArgs": "MyProject\\$(OutDir)MyProject.dll"
}
Or using $(TargetPath) it would be:
"MyRunConfig": {
"commandName": "Executable",
"executablePath": "nunit3-console.exe",
"commandLineArgs": "$(TargetPath)"
}
You can use any of the Pre/Post-Build Macros. I typically go the "Edit Pre-build..." dialog (on the project properties "Build Events" page) and use its Macros button so I can see what they each resolve to.
I couldn't find this macro support documented anywhere by Microsoft, but it works for me in .NET 5.0 projects.
Solution 2:[2]
I just upgraded to the latest version of VS2022 v17.2.0. It does not work using macro in workingDirectory in launchsettings.json. When I launch debug in VS, it throws an error that says the macro variable is not available.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Bill Menees |
| Solution 2 |
