This is an old revision of the document!
Table of Contents
.NET Development
.NET brings a professional .NET runtime to Linux-based PCs like the ComfilePi. The Blazor and Web Assembly technologies 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.
<html><center>A .NET real-time web application running on the ComfilePi</center></html>
Download the source Code for the application demonstrated in the video above.
See also the .NET IoT Libraries API Reference.
Install the .NET SDK on the ComfilePi
Bookworm
.NET 10 SDK
Starting with .NET 10, Microsoft is publishing ARM64 Linux packages. Follow Microsoft's Debian 12 instructions to install the .NET 10 SDK on a ComfilePi running the Bookworm OS.
.NET 9 SDK
Prior to .NET 10, Microsoft had not published ARM64 packages for the .NET SDK, so we filled that gap in our Bookworm OS by creating our own .NET SDK installation packages.
sudo apt update sudo apt install cpi-dotnet-sdk-9.0
.NET 8 SDK
Prior to .NET 10, Microsoft had not published ARM64 packages for the .NET SDK, so we filled that gap in our Bookworm OS by creating our own .NET SDK installation packages.
sudo apt update sudo apt install cpi-dotnet-sdk-8.0
Bullseye
ComfilePi OS images dated 2022-07-26 or later have the .NET SDK already installed. Verify by running the command dotnet –version in a terminal. If you need a later version than that which is installed, use the manually installation process below.
Any OS
Any version of the .NET SDK can be installed manually using the following commands.
DOTNET_VERSION=10.0 # Choose your version wget https://builds.dotnet.microsoft.com/dotnet/scripts/v1/dotnet-install.sh chmod +x dotnet-install.sh sudo ./dotnet-install.sh --channel $DOTNET_VERSION --install-dir /opt/Microsoft/dotnet sudo ln -s /opt/Microsoft/dotnet/dotnet /usr/local/bin/dotnet # Create a configuration file telling the system where to find the .NET runtime sudo mkdir /etc/dotnet sudo bash -c 'echo /opt/Microsoft/dotnet/ >> /etc/dotnet/install_location'
Test the installation by running <html>
dotnet --version
</html> in a terminal.
Workaround for .NET ARM Linux Garbage Collection Bug (.NET 8 & 9 Only)
Important - Due to a bug in the .NET runtime, it may be necessary to restrict the .NET garbage collector's memory limit on devices with small amounts of memory (e.g. a Raspberry Pi) or .NET applications may abort prematurely. To set the garbage collector's memory limit, create or open the file /etc/environment, and add the following line to the file.
DOTNET_GCHeapHardLimitPercent=32
Then reboot.
For more information about this setting, see Microsoft's official documentation.
Install the .NET 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 2022 or later and install it on a development PC. When installing, be sure to select the options for .NET development. It will install both the Visual Studio IDE and the .NET SDK.
* Download the .NET 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 SDK.
Create in a .NET Project
.NET projects can be created using the dotnet command line interface (a.k.a. the .Net CLI) or using the Visual Studio project creation templates.
Using Visual Studio
Creating and Building a Project
To create a .NET 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.
Using the .NET CLI
Creating and Building a Project
To create a .NET 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.
Publishing, Deploying, and Running a .NET Application
To get a .NET application from your development environment to a ComfilePi, you need to perform the following steps in order:
- Publish the application for the ComfilePi's CPU architecture and operating system.
- Deploy the resulting binaries to a ComfilePi panel PC.
- Execute the binaries on the ComfilePi panel PC.
Those steps can all be done using using Visual Studio, the dotnet CLI, and/or Visual Studio Code.
Debugging a Project
To deploy to, launch and debug .NET applications on the ComfilePi from within Visual Studio, use our Remote .NET Debugger Visual Studio Extension
See also Debug .NET apps on the Raspberry Pi.


