Example .NET app¶
This how-to guide covers the steps, decisions, and implementation details that are unique when crafting a snap of an app built using .NET. We’ll work through the aspects unique to .NET-based apps by examining an existing recipe.
Example whatime recipe¶
The following code comprises the recipe of a .NET project, whatime. This project is a CLI command for returning the current time in cities across the globe.
whatime recipe
name: whatime
version: "1.0.0"
grade: devel
summary: Get the current time in various cities around the world
description: |
Whatime is able to get you the current time in several different cities
around the world.
base: core22
confinement: devmode
parts:
whatime:
plugin: dotnet
dotnet-build-configuration: Release
dotnet-self-contained-runtime-identifier: linux-x64
source: .
build-packages:
- dotnet-sdk-6.0
stage-packages:
- libicu70
apps:
whatime:
command: Whatime
Add a part written for .NET¶
parts:
whatime:
plugin: dotnet
dotnet-build-configuration: Release
dotnet-self-contained-runtime-identifier: linux-x64
source: .
build-packages:
- dotnet-sdk-6.0
stage-packages:
- libicu70
.NET parts are built with the dotnet plugin.
To add a .NET part:
Declare the general part keys, such as
source
,override-build
, and so on.Set
plugin: dotnet
.If you need to override the build configuration, set
dotnet-build-configuration
to the name of a configuration.If you need to build the project as a single binary:
In the
.csproj
file, add the following to the<PropertyGroup>
tag:<PublishSingleFile>true</PublishSingleFile>
Set
dotnet-self-contained-runtime-identifier
to the target architecture’s runtime identifier.
For
build-packages
, list any required .NET SDK packages needed for build time.