Debug Azure IoT Edge C# Remote Linux Module Container with Visual Studio 2019 Version 16.3

Renlong Tu

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.

Prerequisites

Setup Your Linux machine

Setup Your Development Machine

Debug C# Module Container Running in Remote Edge Device

  1. 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.
  2. In the Add Module wizard, select C# Module, and replace localhost:5000 with your own registry info, then click Add:
  3. 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.
  4. Click Edge project, and change Target Configuration to Debug

  5. 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.
  6. Since we’re using a private container registry, use the following Docker command to sign in.

  7. 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:

  8. Click Debug -> Attach to Process, set Connection Type to Docker (Linux Container) and click Find… 

  9. Click Add… button from Select Docker Container dialog, and input your remote Linux machine’s IP, username and password. 

  10. 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.
  11. Select process dotnet to attach.
  12. If everything works fine, now you can debug your C# module in Visual Studio:

Summary

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 vsciet@microsoft.com.

Renlong Tu
Renlong Tu

Follow    

0 comments

Leave a comment