json – Escape backslashes in a Visual Studio template parameter


Creating a Visual Studio project template, I need to use the $solutiondirectory$ parameter in the “commandLineArgs of a launchSettings.json file. $solutiondirectory$ return a string with single backslashes but json requires double (escaped) back slashes. How can I escape the single backslashes in the string returned by $solutiondirectory$?
The template folder contains the “start.scr” file.

The launchSetting json file with a wrong “commandLineArgs” value:

{
  "profiles": {
    "$projectname$": {
      "commandName": "Executable",
      "executablePath": "C:\\Program Files\\Autodesk\\AutoCAD 2025\\acad.exe",
      "commandLineArgs": "/nologo /b \"$solutiondirectory$\\$projectname$\\start.scr\""
    }
  }
}

The start.scr file works as expected:

netload "$solutiondirectory$\$projectname$\bin\Debug\$projectname$.dll" 

Leave a Reply

Your email address will not be published. Required fields are marked *