最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

json - Escape backslashes in a Visual Studio template parameter - Stack Overflow

programmeradmin3浏览0评论

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.

Typically, $solutiondirectory$ contains: C:\Users\username\source\repos\Acad2025Plugin. How can I escape the single backslashes in the string returned by $solutiondirectory$to get: C:\\Users\\username\\source\\repos\\Acad2025Plugin?

The template is based on this one, but I want to avoid the template being dependant to the LEGACYCODESEARCH sysvar settings by using full paths.

The launchSetting json file with a wrong "commandLineArgs" value (C:\Users\username\source\repos\Acad2025Plugin\\Acad2025Plugin\\start.scr):

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

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.

Typically, $solutiondirectory$ contains: C:\Users\username\source\repos\Acad2025Plugin. How can I escape the single backslashes in the string returned by $solutiondirectory$to get: C:\\Users\\username\\source\\repos\\Acad2025Plugin?

The template is based on this one, but I want to avoid the template being dependant to the LEGACYCODESEARCH sysvar settings by using full paths.

The launchSetting json file with a wrong "commandLineArgs" value (C:\Users\username\source\repos\Acad2025Plugin\\Acad2025Plugin\\start.scr):

{
  "profiles": {
    "$projectname$": {
      "commandName": "Executable",
      "executablePath": "C:\\Program Files\\Autodesk\\AutoCAD 2025\\acad.exe",
      "commandLineArgs": "/nologo /b \"$solutiondirectory$\\$projectname$\\start.scr\""
    }
  }
}
Share Improve this question edited Mar 25 at 12:34 gileCAD asked Mar 16 at 19:30 gileCADgileCAD 2,5132 gold badges12 silver badges12 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

Just escape each backslash with a slash...

{...
"commandLineArgs": "/nologo /b \"$solutiondirectory$/\/\$projectname$/\/\start.scr/\""
...}
发布评论

评论列表(0)

  1. 暂无评论