You can skip the Background (as per previous post) for building and deploying a .NET Core app on the desktop for the RPi and just follow the steps here. Or read that first for a better understanding. This includes publishing for IoT-Core and Raspbian OS’s.

Scenario

  • Desktop with Visual Studio or VIsual Studio Code installed.
  • Want to create, edit, build a .NET Core app on the desktop for IoT-Core & Raspbian
  • .NET Core is available on the RPi
    • Can just copy it there as previous
  • Assume a writeable share is available on the Pi to deploy the Published build by copying it.
    • And the share is connected to the desktop.
    • File sharing on IoT-Core here
    • Requires Samba with Raspbian How to here.

Visual Studio Code

Requires .NET Core SDK installed on desktop (Not just the runtimes or a specific os-rid binary). Is a link on the following. Install VS Code from here

For IoT-Core

  • In VS Code on the desktop, in the project folder, run the command:
    dotnet publish --runtime win-arm --framework 3.1 --self-contained false
  • In File Explorer, browse to \bin\Debug\netcoreapp3.1\win-arm
  • Copy the Publish folder
  • Paste that into the RPi share (on the desktop)..
  • If building a Quickstart:
    • Run get-iothub as previous, set up an IoT Hub or just select and existing one.
    • Generate the connection strings as previous in get-iothub.
    • Save the set-env.ps1 file to a suitable location, including the .NET settings if using the copy-paste method.
    • Edit it for the location of .NET Core on the device and copy that to the share.
  • In a Remote PowerShell terminal on the device, in the folder that is being shared:
    • Run ./set-env.ps1
  • In that folder run projectname.exe

For Raspbian

As per above except:

  • The command is: dotnet publish --runtime linux-arm --framework 3.1 --self-contained false
  • Copy the folder \bin\Debug\netcoreapp3.1\linux\arm\Publish to the share on the RPi.
  • Create a Bash Shell script set-env.sh instead of the PS script, edit and copy that to the share.
  • On a terminal on the RPi (eg a Remote ssh client, Putty or LXTerminal on the device), in the shared folder:
    • Run tr -d '\r' < set-env.sh > set-env2.sh
      This fixes up some DOS style line endings.
    • Run source ./set-env2.sh
    • Run ./projectname
      • Hint: if you have problems running it run chmod ./projectnname first.

Visual Studio

IoT-Core

  • Load the project
  • Right-click on the project in Solution Explorer and select Publish
  • Choose the Folder option, not the Azure Webjobs.
  • Click on Edit and set the following options:
    • Debug
    • V 3.1
    • Framework Dependant
    • Target win-arm
  • Publish
  • Run the app as above after setting the environment variables.

Raspbian

As above but the target os-rid is linux-arm


A PPT presentation on .NET Core on the Pi


PS: Remember only the device apps will run on the Pi.

Here is a link specifically about .NET Core (C#) on VS Code.

2DO: Debugging

In the meantime (as on previous post): “Scott Hansleman dicusses remote debugging on the Pi using VS Code here Dave Glover also discusses it here and here. These cover some automation options for deploying and debugging in VS Code. More on this later.”


 TopicSubtopic
   
 This Category Links 
Category:IoT Index:IoT
  Next: > .NET Core on IoT
<  Prev:   .NET Core on IoT