[英]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 中使用打开文件夹模式
Right-click the Python (.py) startup file in Solution Explorer choose "Set as Startup Item"在解决方案资源管理器中右键单击 Python (.py) 启动文件选择“设置为启动项”
Right-click the Python (.py) startup file in Solution Explorer and select Debug and Launch Settings.右键单击解决方案资源管理器中的 Python (.py) 启动文件和 select 调试和启动设置。
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"
}
]
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.