====== .NET Development ======
.NET 5 and later brings a professional .NET runtime to Linux-based PCs like the [[index|ComfilePi]].
Graphical User Interfaces and HMIs can now be created for Linux using the latest version of Visual Studio, .NET and C#. See the following GUI frameworks.
^ Framework ^ Description ^
| [[winforms:index|ComfileTech.Winforms]] | A port of the Mono Winforms implementation to .NET 10 |
| [[https://dotnet.microsoft.com/apps/aspnet/web-apps/blazor|Blazor]] | Create both remote and local UIs using web technologies. [[.:dotnet_core_development:blazor_demo:index|Demonstration]]. |
| [[https://avaloniaui.net/|Avalonia]] | Mature, open-source, XAML/C# cross-platform .NET UI framework with strong Linux desktop support |
| [[https://platform.uno/|Uno Platform]] | XAML/C# cross-platform .NET UI framework using WinUI-style APIs; supports Linux desktop and embedded Linux targets. |
| [[https://gircore.github.io/|Gir.Core]] | C# bindings for GObject-based libraries such as GTK; good for native GTK 4 / GNOME-style Linux apps with .NET. |
| [[https://github.com/aprillz/MewUI|MewUI]] | Newer lightweight, code-first .NET GUI framework aimed at NativeAOT and small-footprint desktop utilities. |
===== Install the .NET SDK on the ComfilePi =====
=== Trixie ===
== .NET 10 SDK ==
The ComfilePi Trixie OS includes [[https://learn.microsoft.com/en-us/dotnet/core/install/linux-debian?tabs=dotnet10#debian-12|Microsoft's Debian repository]] and the .NET SDK is installed by default. Simply use ''apt'' to install or uninstall the ''dotnet*'' packages.
=== Bookworm ===
== .NET 10 SDK ==
Starting with .NET 10, Microsoft is publishing ARM64 Linux packages. Follow [[https://learn.microsoft.com/en-us/dotnet/core/install/linux-debian?tabs=dotnet10#debian-12|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 dotnet --version in a terminal.
=== Workaround for .NET ARM Linux Garbage Collection Bug (.NET 8 & 9 Only) ===
**Important** - Due to [[https://github.com/dotnet/runtime/issues/95257|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 [[https://learn.microsoft.com/en-us/dotnet/core/runtime-config/garbage-collector#heap-limit-percent|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:
* [[https://visualstudio.microsoft.com/downloads/|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.
* [[https://dotnet.microsoft.com/download/dotnet/|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
* [[https://visualstudio.microsoft.com/downloads/|Download Visual Studio Code]] as a companion IDE for the ''dotnet'' command line tools available after downloading and installing the .NET SDK.
===== 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.
* [[.:dotnet:deploy:visual_studio:index|Using Visual Studio]]
See also [[https://learn.microsoft.com/en-us/dotnet/iot/deployment|Deploy .NET apps on ARM single-board computers]]
===== Debugging a Project =====
To deploy to, launch and debug .NET applications on the ComfilePi from within Visual Studio or Visual Studio Code using the following extensions.
* [[:comfilepi:dotnet_core_development:remote_debugger:index|Visual Studio Remote .NET Debugger Extension]]
* [[:comfilepi:dotnet_core_development:vscode_remote_debug_configurator:index|Visual Studio Code Remote .NET Debug Configurator Extension]]
See also [[https://docs.microsoft.com/en-us/dotnet/iot/debugging|Debug .NET apps on the Raspberry Pi]].