mu88.Shared
0.5.1
dotnet add package mu88.Shared --version 0.5.1
NuGet\Install-Package mu88.Shared -Version 0.5.1
<PackageReference Include="mu88.Shared" Version="0.5.1" />
paket add mu88.Shared --version 0.5.1
#r "nuget: mu88.Shared, 0.5.1"
// Install mu88.Shared as a Cake Addin #addin nuget:?package=mu88.Shared&version=0.5.1 // Install mu88.Shared as a Cake Tool #tool nuget:?package=mu88.Shared&version=0.5.1
mu88.Shared
General
This repo contains the code of the NuGet package mu88.Shared
, providing the following features:
- Add and configure certain OpenTelemetry features (metrics and traces)
- MSBuild target for building multi-platform Docker images using Microsoft's .NET SDK Container Building Tools
I use this NuGet package to share features and configurations between different .NET apps, hence avoiding the need to implement it repeatedly.
Functionality details
OpenTelemetry
By calling the extension method ConfigureOpenTelemetry
on an instance of Microsoft.Extensions.Hosting.IHostApplicationBuilder
, the following OpenTelemetry features will be enabled:
- Metrics - ASP.NET Core (e.g. request duration) → see here - .NET process information (e.g. process memory) → see here - .NET runtime information (e.g. GC heap size) → see here
- Tracing - ASP.NET Core → see here - Entity Framework Core → see here
To export these data, the .NET configuration parameter OTEL_EXPORTER_OTLP_ENDPOINT
for the OpenTelemetry endpoint receiving the exported metrics and traces must be configured, e.g. via an environment variable. See the official OpenTelemetry docs for more information.
Multi-platform Docker image
With .NET 8, the support for building Docker images without Dockerfile
s has been integrated into the .NET SDK. However, it is not (yet 🫰🏻) possible to build multi-platform Docker images, i.e. a single Docker image built with the .NET SDK Container Building Tools can one target a single platform (e.g. either arm64
or x64
).
The GitHub issue "Design multi-manifest (aka multi-architecture or multi-RID) publishing" tracks the process of adding this functionality to the .NET SDK. Furthermore, it also contains a very first draft of MSBuild logic on how it could work (kudos to the user baronfel). As it's quite a lot of lines, I integrated it into this NuGet package and therefore can reuse it easily.
Usage
By installing the NuGet package, the MSBuild project mu88.Shared.targets
will be added to the .NET project (see here) and the target MultiArchPublish
will become available which can be called like this:
dotnet publish MyProject.csproj /t:MultiArchPublish '-p:ContainerImageTags="dev"' '-p:RuntimeIdentifiers="linux-amd64;linux-arm64"' -p:ContainerRegistry=registry.hub.docker.com
This command will do the following:
- Build the .NET project
MyProject.csproj
for botharm64
andamd64
targeting Linux. - Build and publish a Docker image per platform to the official Docker registry, i.e. there you will see two tags
dev-arm64
anddev-amd64
. - Publish a Docker image with tag
dev
using a new Docker manifest combining bothdev-arm64
anddev-amd64
.
The detour of pushing two platform-specific Docker images to the registry first and combining it afterward into a multi-platform image is a limitation of the current approach.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net8.0
- Microsoft.Extensions.Hosting.Abstractions (>= 8.0.0)
- OpenTelemetry.Exporter.OpenTelemetryProtocol (>= 1.9.0)
- OpenTelemetry.Extensions.Hosting (>= 1.9.0)
- OpenTelemetry.Instrumentation.AspNetCore (>= 1.9.0)
- OpenTelemetry.Instrumentation.EntityFrameworkCore (>= 1.0.0-beta.12)
- OpenTelemetry.Instrumentation.Process (>= 0.5.0-beta.7)
- OpenTelemetry.Instrumentation.Runtime (>= 1.9.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.