This sample explores how a native WinUI 3 desktop application can call into a C# library that has been published using NativeAOT. The important idea is that MyDotNetLib is compiled into a native DLL, allowing the C++/WinRT app to consume exported functionality without requiring the full .NET runtime to be present at execution time.
NativeAotApp
|-- NativeAotApp/ C++/WinRT WinUI 3 desktop application
`-- MyDotNetLib/ C# library published as a NativeAOT native DLL
NativeAotAppis the native desktop front end built with C++/WinRT.MyDotNetLibis authored in C# but published as a NativeAOT binary.- Publishing with NativeAOT produces a native DLL that can be consumed like a native dependency rather than a typical managed assembly.
- This makes the sample useful for experimenting with native interop patterns where the producer is written in C# but the consumer is not a .NET application.
- The solution is intentionally small so you can focus on the publish step, the produced binary, and the consumption path from the WinUI 3 app.
- Open
NativeAotApp.slnin Visual Studio 2022. - Restore packages and confirm both .NET SDK support and C++ desktop tooling are installed.
- Build the solution for a supported platform such as
x64orARM64. - Publish
MyDotNetLibas NativeAOT before launching the app so the expected native output exists.
Before running the app, publish the .NET library as NativeAOT using dotnet CLI tool:
- Navigate to the library folder
..\MyDotNetLib - Open PowerShell and run
dotnet publish -r win-x64 -c Release - Run the NativeAotApp