在 Windows 到 Raspberry Pi 上使用 VS Code 进行远程调试
Remote debugging with VS Code on Windows to a Raspberry Pi
我需要帮助来设置我的 vscode 以便在我的 RPi 4 (Raspberry Pi OS x64) 上部署和调试 dotnet 应用程序,因为我无法附加 vscode 调试器。
应用程序已正确构建并部署在我的 RPi 上,我可以使用命令 dotnet ~/MyFirstApp/MyFirstApp.dll
通过 ssh 运行 它,但是当我尝试使用调试 运行 它时vscode 的函数 returns 出现以下错误:
Could not execute because the specified command or file was not found.
Possible reasons for this include:
* You misspelled a built-in dotnet command.
* You intended to execute a .NET program, but dotnet-~/MyFirstApp/MyFirstApp.dll does not exist.
* You intended to run a global tool, but a dotnet-prefixed executable with this name could not be found on the PATH.
这里是所有文件:
MyFirstApp.cs
Console.WriteLine("Hello, World!");
MyFirstApp.csproj
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>
.vscode/launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch (remote)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "RaspberryPiDeploy",
"program": "~/.dotnet/dotnet",
"args": ["~/${workspaceFolderBasename}/${workspaceFolderBasename}.dll"],
"cwd": "~/${workspaceFolderBasename}",
"stopAtEntry": false,
"console": "internalConsole",
"pipeTransport": {
"pipeCwd": "${workspaceFolder}",
"pipeProgram": "ssh",
"pipeArgs": [
"pi@192.168.2.122"
],
"debuggerPath": "~/vsdbg/vsdbg"
}
}
]
}
.vscode/tasks.json
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"command": "dotnet",
"type": "process",
"args": [
"build",
"${workspaceFolder}/MyFirstApp.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
},
{
"label": "RaspberryPiPublish",
"command": "sh",
"type": "shell",
"dependsOn": "build",
"windows": {
"command": "cmd",
"args": [
"/c",
"\"dotnet publish -r linux-arm64 -o bin\linux-arm64\publish --no-self-contained\""
],
"problemMatcher": []
}
},
{
"label": "RaspberryPiDeploy",
"type": "shell",
"dependsOn": "RaspberryPiPublish",
"presentation": {
"reveal": "always",
"panel": "new",
"close": true
},
"windows": {
"command": "scp -r bin\linux-arm64\publish\* pi@192.168.2.122:${workspaceFolderBasename}"
},
"problemMatcher": []
}
]
}
可以应用两种不同类型的构建:Self-contained 和 Framework-dependent。
Self-contained 构建需要在 MyFirstApp 上 运行 chmod +x
(感谢@PMF 的建议):
launch.json
{
"name": ".NET Remote Launch - Self-contained",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "RaspberryPiDeploySelfContained",
"program": "~/MyFirstApp/MyFirstApp",
"args": [],
"cwd": "~/MyFirstApp",
"stopAtEntry": false,
"console": "internalConsole",
"pipeTransport": {
"pipeCwd": "${workspaceRoot}",
"pipeProgram": "ssh",
"pipeArgs": [
"pi@192.168.2.122"
],
"debuggerPath": "~/vsdbg/vsdbg"
}
}
tasks.json
{
"label": "RaspberryPiPublishSelfContained",
"command": "sh",
"type": "shell",
"dependsOn": "build",
"windows": {
"command": "cmd",
"args": [
"/c",
"\"dotnet publish -r linux-arm64 -o bin\linux-arm64\publish\""
],
"problemMatcher": []
}
},
{
"label": "RaspberryPiDeploySelfContained",
"type": "shell",
"dependsOn": "RaspberryPiPublishSelfContained",
"presentation": {
"reveal": "always",
"panel": "new",
"close": true
},
"windows": {
"command": "scp -r bin\linux-arm64\publish\* pi@192.168.2.122:${workspaceFolderBasename}; ssh pi@192.168.2.122 chmod +x \"${workspaceFolderBasename}/${workspaceFolderBasename}\""
},
"problemMatcher": []
}
这个解决方案有效,但是,考虑到它是一个“self-contained”应用程序,它需要更多时间来复制所有依赖项并且需要更多磁盘 space。
Framework-dependent 解决方案需要复制更少的文件(更少的时间和磁盘 space 来部署和测试它):
launch.json:我必须设置 args
字段提供路径 /home/pi/MyFirstApp/MyFirstApp.dll
,我不明白为什么,但给出了路径~/MyFirstApp/MyFirstApp.dll
返回错误 Could not execute because the specified command or file was not found.
{
"name": ".NET Remote Launch - Framework-dependent",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "RaspberryPiDeploy",
"program": "~/.dotnet/dotnet",
"args": ["/home/pi/MyFirstApp/MyFirstApp.dll"],
"cwd": "~/MyFirstApp",
"stopAtEntry": false,
"console": "internalConsole",
"pipeTransport": {
"pipeCwd": "${workspaceRoot}",
"pipeProgram": "ssh",
"pipeArgs": [
"pi@192.168.2.122"
],
"debuggerPath": "~/vsdbg/vsdbg"
}
}
tasks.json
{
"label": "RaspberryPiPublish",
"command": "sh",
"type": "shell",
"dependsOn": "build",
"windows": {
"command": "cmd",
"args": [
"/c",
"\"dotnet publish -r linux-arm64 -o bin\linux-arm64\publish --no-self-contained\""
],
"problemMatcher": []
}
},
{
"label": "RaspberryPiDeploy",
"type": "shell",
"dependsOn": "RaspberryPiPublish",
"presentation": {
"reveal": "always",
"panel": "new",
"close": true
},
"windows": {
"command": "scp -r bin\linux-arm64\publish\* pi@192.168.2.122:\"~/${workspaceFolderBasename}\""
},
"problemMatcher": []
}
我需要帮助来设置我的 vscode 以便在我的 RPi 4 (Raspberry Pi OS x64) 上部署和调试 dotnet 应用程序,因为我无法附加 vscode 调试器。
应用程序已正确构建并部署在我的 RPi 上,我可以使用命令 dotnet ~/MyFirstApp/MyFirstApp.dll
通过 ssh 运行 它,但是当我尝试使用调试 运行 它时vscode 的函数 returns 出现以下错误:
Could not execute because the specified command or file was not found.
Possible reasons for this include:
* You misspelled a built-in dotnet command.
* You intended to execute a .NET program, but dotnet-~/MyFirstApp/MyFirstApp.dll does not exist.
* You intended to run a global tool, but a dotnet-prefixed executable with this name could not be found on the PATH.
这里是所有文件:
MyFirstApp.cs
Console.WriteLine("Hello, World!");
MyFirstApp.csproj
<Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <OutputType>Exe</OutputType> <TargetFramework>net6.0</TargetFramework> <ImplicitUsings>enable</ImplicitUsings> <Nullable>enable</Nullable> </PropertyGroup> </Project>
.vscode/launch.json
{ "version": "0.2.0", "configurations": [ { "name": ".NET Core Launch (remote)", "type": "coreclr", "request": "launch", "preLaunchTask": "RaspberryPiDeploy", "program": "~/.dotnet/dotnet", "args": ["~/${workspaceFolderBasename}/${workspaceFolderBasename}.dll"], "cwd": "~/${workspaceFolderBasename}", "stopAtEntry": false, "console": "internalConsole", "pipeTransport": { "pipeCwd": "${workspaceFolder}", "pipeProgram": "ssh", "pipeArgs": [ "pi@192.168.2.122" ], "debuggerPath": "~/vsdbg/vsdbg" } } ] }
.vscode/tasks.json
{ "version": "2.0.0", "tasks": [ { "label": "build", "command": "dotnet", "type": "process", "args": [ "build", "${workspaceFolder}/MyFirstApp.csproj", "/property:GenerateFullPaths=true", "/consoleloggerparameters:NoSummary" ], "problemMatcher": "$msCompile" }, { "label": "RaspberryPiPublish", "command": "sh", "type": "shell", "dependsOn": "build", "windows": { "command": "cmd", "args": [ "/c", "\"dotnet publish -r linux-arm64 -o bin\linux-arm64\publish --no-self-contained\"" ], "problemMatcher": [] } }, { "label": "RaspberryPiDeploy", "type": "shell", "dependsOn": "RaspberryPiPublish", "presentation": { "reveal": "always", "panel": "new", "close": true }, "windows": { "command": "scp -r bin\linux-arm64\publish\* pi@192.168.2.122:${workspaceFolderBasename}" }, "problemMatcher": [] } ] }
可以应用两种不同类型的构建:Self-contained 和 Framework-dependent。
Self-contained 构建需要在 MyFirstApp 上 运行
chmod +x
(感谢@PMF 的建议):launch.json
{ "name": ".NET Remote Launch - Self-contained", "type": "coreclr", "request": "launch", "preLaunchTask": "RaspberryPiDeploySelfContained", "program": "~/MyFirstApp/MyFirstApp", "args": [], "cwd": "~/MyFirstApp", "stopAtEntry": false, "console": "internalConsole", "pipeTransport": { "pipeCwd": "${workspaceRoot}", "pipeProgram": "ssh", "pipeArgs": [ "pi@192.168.2.122" ], "debuggerPath": "~/vsdbg/vsdbg" } }
tasks.json
{ "label": "RaspberryPiPublishSelfContained", "command": "sh", "type": "shell", "dependsOn": "build", "windows": { "command": "cmd", "args": [ "/c", "\"dotnet publish -r linux-arm64 -o bin\linux-arm64\publish\"" ], "problemMatcher": [] } }, { "label": "RaspberryPiDeploySelfContained", "type": "shell", "dependsOn": "RaspberryPiPublishSelfContained", "presentation": { "reveal": "always", "panel": "new", "close": true }, "windows": { "command": "scp -r bin\linux-arm64\publish\* pi@192.168.2.122:${workspaceFolderBasename}; ssh pi@192.168.2.122 chmod +x \"${workspaceFolderBasename}/${workspaceFolderBasename}\"" }, "problemMatcher": [] }
这个解决方案有效,但是,考虑到它是一个“self-contained”应用程序,它需要更多时间来复制所有依赖项并且需要更多磁盘 space。
Framework-dependent 解决方案需要复制更少的文件(更少的时间和磁盘 space 来部署和测试它):
launch.json:我必须设置
args
字段提供路径/home/pi/MyFirstApp/MyFirstApp.dll
,我不明白为什么,但给出了路径~/MyFirstApp/MyFirstApp.dll
返回错误Could not execute because the specified command or file was not found.
{ "name": ".NET Remote Launch - Framework-dependent", "type": "coreclr", "request": "launch", "preLaunchTask": "RaspberryPiDeploy", "program": "~/.dotnet/dotnet", "args": ["/home/pi/MyFirstApp/MyFirstApp.dll"], "cwd": "~/MyFirstApp", "stopAtEntry": false, "console": "internalConsole", "pipeTransport": { "pipeCwd": "${workspaceRoot}", "pipeProgram": "ssh", "pipeArgs": [ "pi@192.168.2.122" ], "debuggerPath": "~/vsdbg/vsdbg" } }
tasks.json
{ "label": "RaspberryPiPublish", "command": "sh", "type": "shell", "dependsOn": "build", "windows": { "command": "cmd", "args": [ "/c", "\"dotnet publish -r linux-arm64 -o bin\linux-arm64\publish --no-self-contained\"" ], "problemMatcher": [] } }, { "label": "RaspberryPiDeploy", "type": "shell", "dependsOn": "RaspberryPiPublish", "presentation": { "reveal": "always", "panel": "new", "close": true }, "windows": { "command": "scp -r bin\linux-arm64\publish\* pi@192.168.2.122:\"~/${workspaceFolderBasename}\"" }, "problemMatcher": [] }