NativeSdk 0.5.0
See the version list below for details.
<Sdk Name="NativeSdk" Version="0.5.0" />
#:sdk NativeSdk@0.5.0
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
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.