Remote development and debugging with Visual Studio and Mono kb-12

Octavo / Beaglebone Black  

This article will demonstrate how to perform remote development and remote debugging from Visual Studio on a Windows desktop onto Linux and Mono on a BeagleBone Black or OSD3358 running the default Debian Linux distribution.

Preparation

  1. Ensure you have a working Debian OS installed on an SD card of 8Gb or larger
  2. Ensure that you have a working connection to the internet from the Linux system
  3. Ensure that you have a working installation of Visual Studio 2015
  4. Complete the steps in this KB article so that we can share files between the Windows and Linux system: http://kb.pervasive.digital/Home/Detail/setting-up-samba-directory-sharing
  5. Make sure you are running the latest Mono 4.6.1 or later. See: http://kb.pervasive.digital/Home/Detail/update-to-the-latest-version-of-mono

Procedure

  1. On the Linux system (instructions from : https://github.com/techl/MonoRemoteDebugger)
    1. Make sure that you have unzip installed:
      debian@beaglebone:~$ sudo apt-get install unzip
       
    2. Download the MonoRemoteDebugger.Server
      debian@beaglebone:~$ wget https://github.com/techl/MonoRemoteDebugger/releases/download/v1.0.10/MonoRemoteDebugger.Server.zip
       
    3. Extract the downloaded file
      debian@beaglebone:~$ unzip -d MonoRemoteDebugger.Server MonoRemoteDebugger.Server.zip
       
    4. Start the remote debugger server
      debian@beaglebone:~$ cd MonoRemoteDebugger.Server
      debian@beaglebone:~/MonoRemoteDebugger.Server$ mono MonoRemoteDebugger.Server.exe
      2016-10-09 22:45:27.4528|TRACE|MonoRemoteDebugger.SharedLib.Server.MonoDebugServer|Start announcing
      2016-10-09 22:45:27.8846|INFO|MonoRemoteDebugger.SharedLib.Server.MonoDebugServer|Waiting for client
    5. Note that you cannot run the remote debugger in the background. Just leave it running in this window and open up a new window with Tera Term or whatever mechanism you are using to open terminal sessions on the Linux system.
       
    6. You must repeat step (4) each time you reboot the Linux system, log out, or otherwise stop the remote debugger server.
  2. On the Windows system:
    1. Install the Mono Remote Debugger extension for Visual Studio from : https://visualstudiogallery.msdn.microsoft.com/b904ed43-4604-4b5b-a80b-93146192a64e
       
    2. Mount your home directory (or other share) on your windows system so that we can edit files in Visual Studio and save them to the Linux filesystem:
      C:\>net use Q: \\10.0.0.177\debian /u:debian *
      Type the password for \\10.0.0.177\debian:
      The command completed successfully.
       
    3. Create a directory for our projects:

      C:\>q:
      Q:\>mkdir projects
       

    4. Start VS2015 and create a new solution and project with File->New Solution :

    5. Enter and save the following program:
       

      using System;

      namespace RemoteAppExperiment
      {
          class Program
          {
              static void Main(string[] args)
              {
                  Console.WriteLine("Hello (remote) World...");
                  for (var i = 0; i<10; ++i)
                  {
                      Console.WriteLine("Iteration {0}", i);
                  }
                  Console.WriteLine("Done");
              }
          }
      }

    6. Edit the project file
      1. Right click on the project "RemoteAppExperiment" (the project, not the solution) and select "Unload project" and then "Edit RemoteAppExperiment,csproj"
         
      2. Find this line:
      3. And add this line right after the CSharp.targets line you found in the previous step:

         (sorry these are not copyable, but the kb editor got a little upset with the xml for some reason)

         
      4. This will prevent the the addition of an attribute that is not supported in the Mono world.
         
      5. Right click on the project in the Solution Explorer again, and select "Reload Project".  Answer YES if you are asked to close the file.  You may also be warned that this is an untrusted project (because it is on a file share). Answer OK if prompted.
         
    7. Now, back on the Linux system
      1. Get into the working directory:
        debian@beaglebone:~$ cd ~/projects/RemoteAppExperiment
         
      2. And build your solution using xbuild (which is the Mono equivalent of msbuild):
        debian@beaglebone:~/projects/RemoteAppExperiment$ xbuild RemoteAppExperiment.sln
         
    8. Attach the debugger to the remote system:
       
      1. In Visual Studio, place a breakpoint on a line of code (for instance, the first Console.WriteLine).
      2. From the toolbar, select MonoRemoteDebugger and click on "Debug with Mono (remote)"
      3. Enter the IP address of your remote system (10.0.0.177 in my case).  The UI may or may not find your remote system automatically, but for me it didn't, and I needed to manually enter the IP address:

         
      4. Your program will start running on the Linux system, and the debugger will break on your breakpoint.  You can use the stepping instuctions (step-over, step-into, continue) and you can examine variable values and use the watch window just as with local programs.  You can watch the Linux terminal window to see the output from your program.
      5. It is normal to see an "Unexpected end of file" error on the Linux output where your program finishes.

Conclusion

Remote debugging gives you full access to the specialized hardware on your BeagleBone/GHI-OSD3358 device while also allowing you to work in a powerful, comfortable and familiar environment on your desktop Windows system.

 

 
 
comments powered by Disqus
 

Similar Articles

 

Tags