User Tools

Site Tools



.NET Core Development

.NET Core brings a professional .Net runtime to Linux-based PCs like the ComfilePi. Although there are not yet any GUI frameworks like Winforms or XAML (out-of-the-box at least), .NET Core 3 comes with the new Blazor and Web Assembly technologies that can be used to build GUI applications for the ComfilePi's modern web browser.

Blazor allows both client and server to be programmed almost entirely in C#. The System.Devices.Gpio namespace provides just about everything one would need to do IO on the ComfilePi. Blazor also includes support for real-time web applications that can be viewed and interacted with from multiple local or remote clients.

The following video demonstrates a project running on the ComfilePi, controlling a CP-IO22-A4-2 IO board (mounted on the rear of the ComfilePi). The application, running on the ComfilePi to the right can be viewed and interacted with from the ComfilePi itself, a development PC, or even a smartphone, in real-time.

A .Net Core real-time web application running on the ComfilePi

Download the source Code for the application demonstrated in the video above.

Install the .Net Core SDK on the ComfilePi

Download the .NET Core SDK from and install it on the ComfilePi. The ComfiliePi is an ARM32 device.

# Download the .Net Core SDK archive
wget {URL of .Net Core SDK *.tar.gz file}
# Create the installation folder
sudo mkdir -p /opt/Microsoft/dotnet 
# Extract the archive to `/opt/Microsoft/dotnet` folder
sudo tar -xvf {filename}.tar.gz -C /opt/Microsoft/dotnet
# Create a symbolic link to the `dotnet` executable file
sudo ln -s /opt/Microsoft/dotnet/dotnet /usr/bin/dotnet

Test the installation by running dotnet –version in a terminal window.

Install the .Net Core SDK on a Development PC

It is likely much more convenient to author code on a development PC. To do that there are a few options:

* Download Visual Studio 2019 or later and install it on a development PC. When installing, be sure to select the options for .Net Core development. That will install both the Visual Studio IDE and the .Net Core SDK.

* Download the .Net Core SDK and install install it on development PC. You can then use the dotnet command in a terminal window to create, compile, and publish projects

* Download Visual Studio Code as a companion IDE for the dotnet command line tools available after downloading and installing the .Net Core SDK.

Create, Build, and Publish a .Net Core Application for the ComfilePi

.Net Core projects can be created using the dotnet command line tools or using the Visual Studio project creation templates.

Creating and Building a Project

Using Command Line Tools

To create a .Net Core Server-side Blazor application like that demonstrated in the video above, run dotnet new blazorserver in a terminal window. To build the application run dotnet build from within the project folder.

Using Visual Studio

To create a .Net Core Server-size Blazor application using Visual Studio, create a new Blazor App project.

Build the project just as you would any other Visual Studio project.

Publish a Project for the ComfilePi

Using Command Line Tools

To publish a .Net Core project for the ComfilePi, run dotnet publish -r linux-arm –self-contained false.

If you want to publish a self-contained set of binaries so the .Net Core SDK or runtime does not need to be installed on the ComfilePi, run dotnet publish -r linux-arm –self-contained true. Be aware that a self-contained application will case a very large number of files to generated and copied to the ComfilePi which will likely make iterative development very unproductive.

Using Visual Studio

To publish a .Net Core project using Visual Studio, right-click the project in Visual Studio's Solution Explorer and choose the Publish option. In the Advanced Settings choose the linux-arm runtime. If the .Net Core SDK or runtime is already installed on the ComfilePi, choose the Framework Dependent development mode.

The result will be found in the project's bin\{Debug|Release}\netcoreapp3.0\linux-arm\.

Deploying a Project to the ComfilePi

The result can be copied to the ComfilePi using normal file copy procedures, but it may be more efficient to automate it using plink and pscp which are command-line tools available after downloading and installing Putty. The following is a sample powershell script to both publish and deploy a .Net Core application from a Windows development PC.

$publish_dir = ".\{Project Folder}\bin\Debug\netcoreapp3.0\linux-arm\"
$ip = "{IP Address of the ComfilePi}"
$dest_dir = "/home/pi/{Project Name}"
$user = "pi"
$password = "raspberry"
Remove-Item -r $publish_dir
dotnet publish -r linux-arm --self-contained false
# You need to install putty to use plink and pscp
Write-Host "Creating destination folder"
plink -batch -l $user -pw $password $ip mkdir -p $dest_dir
Write-Host "Removing any existing files in destination folder"
plink -batch -l $user -pw $password $ip rm -rf $dest_dir/*
Write-Host "Deploying the application"
pscp -l $user -pw $password -r $publish_dir\publish\* ${ip}:$dest_dir

Running a Deployed Project on the ComfilePi

After a project has been deployed to the ComfilePi it can be executed with the command dotnet {executable}.

For ASP.Net applications, the project can be run by changing to the project's directory and running the command dotnet {project name}.dll. By default the project will be bound to http://localhost:5000, but that will only make the project available to the ComfilePi's browser. To make the project available to external clients, run the command dotnet {project name}.dll --urls

The application can then be accessed either from the ComfilePi's web browser or from any other device with a modern web browser.

The ComfilePi's browser can run the application in kiosk mode using a command like chromium-browser --noeerrdialogs --disable-infobars --kiosk http://localhost:5000

Type Ctrl-C to shutdown the application.

Debugging a Project

The project can be debugged in Visual Studio using Debug–>Attach to Process… from Visual Studio's menu bar.

comfilepi/dotnet_core_development.txt · Last modified: 2020/06/02 16:17 by COMFILE Technology