NativeSdk 0.5.0

There is a newer version of this package available.
See the version list below for details.
<Sdk Name="NativeSdk" Version="0.5.0" />
                    
For projects that support Sdk, copy this XML node into the project file to reference the package.
#:sdk NativeSdk@0.5.0
                    
#:sdk directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.

NativeSdk

A MSBuild SDK package for building Native AOT libraries with C# that can be consumed by native applications.

Requirements

  • .NET 8.0 or later

Installation

Use NativeSdk as your project SDK:

<Project Sdk="NativeSdk/0.5.0">
    <PropertyGroup>
        <TargetFramework>net8.0</TargetFramework>
    </PropertyGroup>
</Project>

This SDK automatically inherits from Microsoft.NET.Sdk, so you don't need to specify it separately.

Features

This SDK automatically configures your project with:

Setting Default Value Description
PublishAot true Enables Native AOT compilation
IsAotCompatible true Marks the project as AOT compatible
NativeLib Shared Builds as a shared/dynamic library
AllowUnsafeBlocks true Enables unsafe code
TrimMode full Full trimming for size optimization
InvariantGlobalization true Invariant globalization mode
EnableTrimAnalyzer true Enables trim compatibility analyzer
EnableAotAnalyzer true Enables AOT compatibility analyzer
TreatWarningsAsErrors true Treats warnings as errors

Debug Configuration

  • Stack trace support enabled
  • Metadata preserved for debugging

Release Configuration

  • Stack trace support disabled
  • Metadata trimmed for smaller binaries

DNNE Integration

This SDK includes DNNE for generating native exports. Use the [UnmanagedCallersOnly] attribute to export functions:

using System.Runtime.InteropServices;

public static class NativeExports
{
    [UnmanagedCallersOnly(EntryPoint = "add")]
    public static int Add(int a, int b) => a + b;
}

Customization

All settings can be overridden in your project file:

<PropertyGroup>
  
  <NativeLib>Shared</NativeLib>
  
  
  <IlcOptimizationPreference>Size</IlcOptimizationPreference>
  
  
  <AllowUnsafeBlocks>false</AllowUnsafeBlocks>
</PropertyGroup>

Building

dotnet publish -c Release -r win-x64
dotnet publish -c Release -r linux-x64
dotnet publish -c Release -r osx-arm64

License

MIT

There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

This package has no dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.5.2 566 12/8/2025
0.5.1 557 12/8/2025
0.5.0 558 12/8/2025