Skip to content

Instantly share code, notes, and snippets.

@jkotas
Created March 8, 2023 03:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jkotas/f70c77015f24b31f00ca37ac67f388fa to your computer and use it in GitHub Desktop.
Save jkotas/f70c77015f24b31f00ca37ac67f388fa to your computer and use it in GitHub Desktop.
Native AOT static linking demo
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<PublishAot>true</PublishAot>
</PropertyGroup>
<ItemGroup>
<NativeLibrary Include="mylibrary.obj" />
<DirectPInvoke Include="mylibrary" />
</ItemGroup>
</Project>
extern int MyMethod();
int MyMethod()
{
return 42;
}
using System.Runtime.InteropServices;
partial class Program
{
static void Main() => Console.WriteLine(MyMethod());
[LibraryImport("MyLibrary")]
private static partial int MyMethod();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment