dotnet / dotnet/diagnostics

Pack dotnet-sos/dotnet-debugger-extensions as AOT tool

Open
#5,851 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
1.3k
Forks
404
Avg merge
2d 5h
Merged PRs (30d)
35

Description

With .NET 10, we can now leverage the standard convention of separating the 'root package' from the 'runtime package' when building AOT tools.

This scalable model allows us to replace the current monolithic infrastructure and its hardcoded list of Microsoft-supported platforms. By adopting this approach, we can easily accommodate community-driven and emerging platforms.

---

### Tutorial: Building a Native AOT Tool

```sh
$ echo 'using static System.Runtime.InteropServices.RuntimeInformation;
Console.WriteLine($"{OSDescription}\n{FrameworkDescription}");' | dotnet run -

Alpine Linux v3.23
.NET 10.0.8

$ dotnet new console -n myaottool
$ cd myaottool
```

**Program.cs**
```c#
using System;

Console.WriteLine("Hello from a Native AOT .NET Tool!");
Console.WriteLine($"Running on: {Environment.OSVersion}");
```

**myaottool.csproj**
```xml


Exe
net10.0
enable
true
true



win-x64;win-x86;win-arm64;

linux-x64;linux-arm;linux-arm64;
linux-musl-x64;linux-musl-arm;linux-musl-arm64;

osx-x64;osx-arm64;

$(RuntimeIdentifier)

```

The runtime tool is now a standalone package. Note that separate builds are required for each supported platform to generate the necessary runtime artifacts.

```sh
# Pack the root package
$ dotnet pack -c Release

# Pack the runtime-specific package (for the current platform)
$ dotnet pack -c Release --ucr

$ find . -name '*pkg'
./bin/Release/myaottool.linux-musl-arm64.1.0.0.nupkg
./bin/Release/myaottool.1.0.0.nupkg
```

We can now push this nupkg to nuget from each "official" machine. The community guys can just place their runtime pack to `/library-packs` in their builds.

test and verify locally (does it work, is it really AOT app etc.):

```sh
$ dotnet tool install --global --add-source bin/Release myaottool

$ myaottool
Hello from a Native AOT .NET Tool!
Running on: Unix 6.12.76.0

$ readelf -p .comment $(realpath $(command -v myaottool))
String dump of section '.comment':
[ 0] GCC: (Alpine 15.2.0) 15.2.0
[ 1c] clang version 20.1.8
[ 31] .NET: ilc 10.0.8-servicing.26229.119+94ea82652cdd4e0f8046b5bd5becbd11461482ca
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.