简体   繁体   English

如何通过 Launch.json 传递 arguments 以在 Visual Studio 2019 中进行调试

[英]How can I pass arguments via Launch.json for debugging in Visual Studio 2019

I am trying to migrate over from Visual Studio Code to Visual Studio 2017. I do not have a project or solution for my code, rather a main.py file is launched with set arguments in order to run.我正在尝试从 Visual Studio Code 迁移到 Visual Studio 2017。我的代码没有项目或解决方案,而是使用 set arguments 启动 main.py 文件以便运行。

I have the current code in my launch.json file我的 launch.json 文件中有当前代码

  "version": "0.2.1",
  "configurations": [
    {
      "project": "project\\myproject\\main.py",
      "name": "MyDebug:Debug",
      "type": "python",
      "request": "launch",
      "pythonPath": "C:\\ProgramData\\Anaconda3\\envs\\custom\\python.exe",
      "program": "${workspaceFolder}\\project\\myproject\\main.py",
      "console": "integratedTerminal",      
      "args": [
        "C:\\Users\\Me\\mytextdoc.txt",
        "-l",
        "DEBUG"
      ]
    },

When I select MyDebug from the Debug dropdown list, the startup item is correctly set as main.py.当我从 Debug 下拉列表中 select MyDebug 时,启动项正确设置为 main.py。 However, my arguments are not used.passed when main.py is called.但是,我的 arguments 没有使用。调用 main.py 时通过。

This code has been pulled from a Visual Studio Code environment and largely unchanged (ie "console": "integratedTerminal").此代码已从 Visual Studio Code 环境中提取,并且基本未更改(即“控制台”:“集成终端”)。

How am I able to pass arguments in Visual Studio 2019?如何在 Visual Studio 2019 中通过 arguments?

Any help much appreciated.非常感谢任何帮助。

I had the same issue, I was able to port the definitions from launch.json to launch.vs.json following Open and run Python code in a folder , but I remained with the problem that scriptArguments is a string instead of an array as args, and using args doesn't work.我遇到了同样的问题,我能够将定义从 launch.json 移植到 launch.vs.json 打开并运行 Python 代码后,我仍然在一个文件夹中作为问题的字符串,并且使用 args 不起作用。 This is extremely annoying because a single string with all the arguments may turn to be very long, and the settings file becomes difficult to manage (a very long arguments string that you cannot break in the json file).这非常烦人,因为包含所有 arguments 的单个字符串可能会变得很长,并且设置文件变得难以管理(非常长的 arguments 字符串,您无法在 json 文件中中断)。 Does anyone have a better solution for this?有没有人对此有更好的解决方案? scriptArguments alternatives? scriptArguments 替代品?

thanks, Emanuel谢谢,伊曼纽尔

Have you taken a look at this guide ?你看过这个指南吗?

Using Open Folder mode in VS在 VS 中使用打开文件夹模式

  1. Right-click the Python (.py) startup file in Solution Explorer choose "Set as Startup Item"在解决方案资源管理器中右键单击 Python (.py) 启动文件选择“设置为启动项”

  2. Right-click the Python (.py) startup file in Solution Explorer and select Debug and Launch Settings.右键单击解决方案资源管理器中的 Python (.py) 启动文件和 select 调试和启动设置。

  3. Choose Default Debugger选择默认调试器

this will create a launch.vs.json file like this这将创建一个像这样的launch.vs.json文件

{
  "version": "0.2.1",
  "defaults": {},
  "configurations": [
    {
      "type": "python",
      "interpreter": "(default)",
      "interpreterArguments": "",
      "scriptArguments": "",
      "env": {},
      "nativeDebug": false,
      "webBrowserUrl": "",
      "project": "python3\\contemplate_koans.py",
      "name": "contemplate_koans.py",
      "workingDirectory": "python3"
    }
  ]
}
  1. Edit "scriptArguments"编辑“脚本参数”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Visual Studio Code launch.json 设置用于调试 Python 模块 - Visual Studio Code launch.json settings for debugging Python modules 如何在Visual Code中设置launch.json来调试C - How can I set up launch.json in Visual Code to debbug C 将对象作为字符串传递以在 VSCode 的 launch.json 文件中进行调试 - Pass object as a string for debugging in VSCode' launch.json file 如何创建 launch.json 以使用 pipenv 脚本? - How can I create a launch.json to use pipenv scripts? 在 Visual Studio Code 中为文件“launch.json”设置 Python 路径 - Setting the Python path in Visual Studio Code for file 'launch.json' 如何设置 VsCode launch.json 用于 python 调试特定 function 等? - How do I set VsCode launch.json for python debugging of specific function among others? 如何通过 launch.json 在 VS 代码中将参数传递给 python 解释器(而不是 python 代码) - How to pass an argument to the python interpreter (not to the python code) in VS code via launch.json 如何在 Visual Studio Code 的 launch.json 中调试 Python 模块 - How to debug a Python module in Visual Studio Code's launch.json 如何从launch.json传递带有特殊字符的参数? - How do I pass an argument with special characters from launch.json? 如何配置 launch.json 以便它可以键入自动响应? - How can I configure launch.json so it could type automatic response?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM