Debug Azure IoT Edge C# Remote Linux Module Container with Visual Studio 2019 Version 16.3
With the 16.3 release of Visual Studio 2019, it starts to support debugging C# in Linux docker containers. This new feature can help developers easily debug remote Azure IoT Edge C# Linux module container.
Let’s see how it works.
Setup Your Linux machine
- Install and config Azure IoT Edge runtime on your remote Linux machine.
- Enable SSH on your remote Linux machine.
- Manage Docker as a non-root user, so that you don’t need to preface the docker command with sudo.
Setup Your Development Machine
- OS: Windows 10
- Visual Studio 2019 with version of 16.3.0 or later, including workloads “.NET desktop development” and “Azure development workload”
- Download and install Azure IoT Edge extension for Visual Studio 2019
- Download and install Docker Desktop for Windows
Debug C# Module Container Running in Remote Edge Device
- Open Visual Studio 2019. In the Create a New Project dialog, search “iot”, and select Azure IoT Edge (Linux amd64), click “next” and enter a name for your project and specify the location, and then click Create.
- In the Add Module wizard, select C# Module, and replace localhost:5000 with your own registry info, then click Add:
- Now there’re two projects in the solution, the first one “IotEdgeModule1” is Azure IoT Edge module project, which is just simple .Net Core project. The other one RemoteEdgeContainerDebug is Azure IoT Edge deployment project.
- Click Edge project, and change Target Configuration to Debug
- Click Show All Files icon as below, a .env file should be displayed under Edge project, open the .env file to input credential for your registry, this credential will be used by Azure IoT Edge runtime to pull module images after deployment.
- Since we’re using a private container registry, use the following Docker command to sign in.
1docker login -u <ACR username> -p <ACR password> <ACR login server>
- Right click on the Edge project and click Build and Push IoT Edge Modules to build, push the Docker image for the C# module. After push is done, open Cloud Explorer by clicking View -> Cloud Explorer, expand your subscription and find the IoT Edge device corresponding to your remote Linux device, right click on the IoT Edge device to create a deployment for it, you need to select the deployment manifest file under the path below:
- Click Debug -> Attach to Process, set Connection Type to Docker (Linux Container) and click Find…
- Click Add… button from Select Docker Container dialog, and input your remote Linux machine’s IP, username and password.
- After successfully connecting to the SSH, then you can choose which container you want to Attach. In our scenario, we should select “IoTEdgeModule1” which is the C# module container. 、
- Select process dotnet to attach.
- If everything works fine, now you can debug your C# module in Visual Studio:
With the new release of Visual Studio 2019, now you can easily debug Azure IoT Edge C# Linux module containers. You can download and try it with Visual Studio 16.3. Additionally, please report any issues you encounter, any feature request you have or other questions to firstname.lastname@example.org.