This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
comfilepi:dotnet_core_development [2022/11/14 12:54] COMFILE Technology [Install the .NET 7 SDK on the ComfilePi] |
comfilepi:dotnet_core_development [2023/11/22 12:25] (current) COMFILE Technology [Create, Build, and Publish a .NET Application for the ComfilePi] |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== .NET 7 Development ====== | + | ====== .NET Development ====== |
- | .NET 7 brings a professional .NET runtime to Linux-based PCs like the ComfilePi. The [[https://dotnet.microsoft.com/apps/aspnet/web-apps/blazor|Blazor and Web Assembly]] technologies can be used to build GUI applications for the ComfilePi's modern web browser. | + | .NET 8 brings a professional .NET runtime to Linux-based PCs like the ComfilePi. The [[https://dotnet.microsoft.com/apps/aspnet/web-apps/blazor|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 [[https://docs.microsoft.com/en-us/dotnet/api/system.device.gpio|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. | Blazor allows both client and server to be programmed almost entirely in C#. The [[https://docs.microsoft.com/en-us/dotnet/api/system.device.gpio|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. | ||
Line 9: | Line 9: | ||
{{ :comfilepi:dotnet_core_blazor.mp4?720x405 }} | {{ :comfilepi:dotnet_core_blazor.mp4?720x405 }} | ||
- | <html><center>A .NET 7 real-time web application running on the ComfilePi</center></html> | + | <html><center>A .NET real-time web application running on the ComfilePi</center></html> |
{{ :comfilepi:comfiletech.comfilepi.io.zip |Download the source Code}} for the application demonstrated in the video above. | {{ :comfilepi:comfiletech.comfilepi.io.zip |Download the source Code}} for the application demonstrated in the video above. | ||
- | See also the [[https://docs.microsoft.com/en-us/dotnet/api/?view=iot-dotnet-1.5|.NET IoT Libraries API Reference]]. | + | See also the [[https://learn.microsoft.com/en-us/dotnet/api/?view=iot-dotnet-latest|.NET IoT Libraries API Reference]]. |
- | ===== Install the .NET 7 SDK on the ComfilePi ===== | + | ===== Install the .NET SDK on the ComfilePi ===== |
**NOTE:** 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. | **NOTE:** 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. | ||
Line 24: | Line 24: | ||
wget https://dotnet.microsoft.com/download/dotnet/scripts/v1/dotnet-install.sh | wget https://dotnet.microsoft.com/download/dotnet/scripts/v1/dotnet-install.sh | ||
chmod +x dotnet-install.sh | chmod +x dotnet-install.sh | ||
- | sudo ./dotnet-install.sh --channel 7.0 --install-dir /opt/Microsoft/dotnet | + | sudo ./dotnet-install.sh --channel 8.0 --install-dir /opt/Microsoft/dotnet |
sudo ln -s /opt/Microsoft/dotnet/dotnet /usr/local/bin/dotnet | sudo ln -s /opt/Microsoft/dotnet/dotnet /usr/local/bin/dotnet | ||
Line 35: | Line 35: | ||
- | ===== Install the .NET 7 SDK on a Development PC ===== | + | ===== 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: | 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 7 development. It will install both the Visual Studio IDE and the .NET 7 SDK. | + | * [[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/7.0|Download the .NET 7 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://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 7 SDK. | + | * [[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. |
- | ===== Create, Build, and Publish a .NET 7 Application for the ComfilePi ===== | + | ===== Create, Build, and Publish a .NET Application for the ComfilePi ===== |
- | .NET 7 projects can be created using the ''dotnet'' command line interface (a.k.a. the .Net CLI) or using the Visual Studio project creation templates. | + | .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 ==== | ==== Using Visual Studio ==== | ||
Line 55: | Line 55: | ||
=== Creating and Building a Project === | === Creating and Building a Project === | ||
- | To create a .NET 7 Server-size Blazor application using Visual Studio, create a new //Blazor App// project. | + | To create a .NET Server-size Blazor application using Visual Studio, create a new //Blazor App// project. |
| {{:comfilepi:blazor_app.png?450|}} | {{:comfilepi:blazor_server.png?450|}} | | | {{:comfilepi:blazor_app.png?450|}} | {{:comfilepi:blazor_server.png?450|}} | | ||
Line 63: | Line 63: | ||
=== Publish a Project for the ComfilePi === | === Publish a Project for the ComfilePi === | ||
- | To publish a .NET 7 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 7 SDK or runtime is already installed on the ComfilePi, choose the //Framework Dependent// development mode. | + | To publish a .NET 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 SDK or runtime is already installed on the ComfilePi, choose the //Framework Dependent// development mode. |
| {{:comfilepi:publish_target.png?450|}} | {{:comfilepi:publish_advanced.png?450|}} | | | {{:comfilepi:publish_target.png?450|}} | {{:comfilepi:publish_advanced.png?450|}} | | ||
Line 73: | Line 73: | ||
=== Creating and Building a Project === | === Creating and Building a Project === | ||
- | To create a .NET 7 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. | + | 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. |
=== Publish a Project for the ComfilePi === | === Publish a Project for the ComfilePi === | ||
- | To publish a .NET 7 project for the ComfilePi, run ''dotnet publish -r linux-arm --self-contained false''. | + | To publish a .NET 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 7 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 cause a very large number of files to be generated and copied to the ComfilePi which will likely make iterative development very unproductive. | + | If you want to publish a self-contained set of binaries so the .NET 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 cause a very large number of files to be generated and copied to the ComfilePi which will likely make iterative development very unproductive. |
Line 85: | Line 85: | ||
===== Deploying a Project to the ComfilePi ===== | ===== 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. The following is a sample powershell script to both publish and deploy a .NET 7 application from a Windows development PC. | + | The result can be copied to the ComfilePi using normal file copy procedures, but it may be more efficient to automate it. The following is a sample powershell script to both publish and deploy a .NET application from a Windows development PC. |
<code powershell> | <code powershell> |