Solving a rather elementary problem and not having mastered the Spartan development conditions for ESP8266 decided to return to the cozy world of .Net in which there is also auto-completion and debugging.
So, we have on hand:
Development will be conducted in Visual Studio Code with the C#
extension installed.
Requires installed .NET Core SDK .
It is also desirable to have a version of Windows 10 1803 , since OpenSSH is installed by default into it. In earlier versions of Windows 10, OpenSSH can be installed via Manage Add-ons. However, this does not prohibit the use of third-party SSH clients.
The first step is to configure SSH access by key. Excellent instructions from Digital Ocean perfectly help with this.
*Note:
Private keys can be stored as separate files in the .ssh folder, but I recommend using the pretty convenient KeePass + KeeAgent combination . KeePass provides secure key storage, and KeeAgent provides keys. In order for it to work with the client built into Windows SSH, you need to activate the appropriate experimental setting. *
Since the official Microsoft repository does not contain packages compiled for ARM32, you must install the .NET Core SDK manually.
First, we need to install the dependencies listed in the documentation .
apt-get install liblttng-ust0 libcurl3 libssl1.0.0 libkrb5-3 zlib1g libicu52 gettext
Now you can install the SDK.
Direct link to the archive with the SDK can be taken from the SDK page on GitHub .
curl -sSL -o dotnet.tar.gz https://dotnetcli.blob.core.windows.net/dotnet/Sdk/release/2.1.401/dotnet-sdk-latest-linux-arm.tar.gz sudo mkdir -p /opt/dotnet && sudo tar zxf dotnet.tar.gz -C /opt/dotnet sudo ln -s /opt/dotnet/dotnet /usr/local/bin
The install script of the remote debugger uses unzip
:
sudo apt-get install unzip
To install the remote debugger, run the following command:
curl -sSL https://aka.ms/getvsdbgsh | bash /dev/stdin -r linux-arm -v latest -l ~/vsdbg
It's all very simple:
mkdir DemoProject cd DemoProject dotnet new console
Open the folder with the project. The C # extension automatically downloads the OmniSharp and .NET Core Debuger packages, if this has not been done before. After that, we will be asked to create assets for building and debugging the project. We agree to this. As a result, the .vscode
folder with the tasks.json
and launch.json
files tasks.json
launch.json
. These files describe the tasks that can be performed and launch configurations. By default, a debugger launch configuration is created, depending on the build task.
The basic idea of launching and debugging on a remote device is to create tasks that collect the project and copy it to the device and launch configuration using the remote debugger.
I will give a description of the finished tasks:
{ "version": "2.0.0", "tasks": [ { "label": "publish", "command": "dotnet", "type": "process", "args": [ "publish", "${workspaceFolder}/DemoProject.csproj" ] }, { "label": "copy-to-device", "dependsOn": "publish", "command": "scp", "type": "process", "args": [ "-r", "-v", "${workspaceFolder}/bin/Debug/netcoreapp2.1/publish/.", "<target_user>@<target_ip>:~/DemoProject/" ] }, ] }
The publish
task invokes the dotnet publish
command, which packages the application and its dependencies in a deployment folder.
The copy-to-device
command uses scp
to copy the published application to a remote device. Pay attention to the point at the end of the path from which copying takes place. If you do not specify it, then during subsequent copying the publish
folder will be placed in the DemoProject
, and will not overwrite it. The dependsOn
parameter indicates that copy-to-device
depends on publish
. Thus, before executing copy-to-device
publish
will be executed.
Next, you need to configure the remote launch and debug configuration:
{ "version": "0.2.0", "configurations": [ { "name": ".NET Core Launch (console)", "type": "coreclr", "request": "launch", "preLaunchTask": "copy-to-device", "program": "~/DemoProject/DemoProject.dll", "args": [], "cwd": "~/DemoProject", "console": "internalConsole", "stopAtEntry": false, "internalConsoleOptions": "openOnSessionStart", "pipeTransport": { "pipeCwd": "${workspaceRoot}", "pipeProgram": "ssh", "pipeArgs": [ "-T", "<target_user>@<target_ip>" ], "debuggerPath": "~/vsdbg/vsdbg", "quoteArgs": true } } ,] }
The "preLaunchTask": "copy-to-device"
parameter "preLaunchTask": "copy-to-device"
indicates that you need to run the copy-to-device
task before starting a debugging session. Thus, each time before debugging, the project will be published and copied to the target device.
The pipeTransport
parameter allows you to configure the use of a remote debugger. In this case, ssh
used as the program providing the transport, but nothing prevents the use of plink.exe
from the putty
program putty
.
After pressing F5, the project builds, copies and launches the application on the remote device. Debugging is completely identical to local.
Note:
After the application was completed, I received the Error from pipe program 'ssh': Process is terminating due to StackOverflowException
message each time Error from pipe program 'ssh': Process is terminating due to StackOverflowException
. Judging by the open issue on GitHub, this is a known debugger problem. But since the error occurs after the debugging is completed, you can ignore this.
→ Setting up Raspian and .NET Core 2.0 on a Raspberry Pi
→ Omnisharp-vscode Remote Debugging On Linux Arm
→ dotnet publish command help
→ Configuring launch.json for C # debugging
→ Visual Studio Code Integrate with External Tools via Tasks
Source: https://habr.com/ru/post/422141/
All Articles