Getting started
This walks through publishing a Kotlin/Native library as a NuGet package and consuming it from a C# project, end to end. It mirrors test-library/build.gradle.kts and the IntegrationTests project in this repo, read those alongside this page for a working reference.
1. Apply the plugin
The plugin id on the Gradle Plugin Portal is io.github.xxfast.kotlin.native.nuget. The same artifacts are on Maven Central under io.github.xxfast.
2. Declare native targets
Every target that should ship a native binary needs a sharedLib binary. Leave baseName unset: the plugin names the native library from packageId (MyCatLib becomes kn_mycatlib.dll on Windows, libkn_mycatlib.dylib on macOS, ...), and the generated C# [DllImport]s that name.
Targets outside the supported set are skipped with a warning; see Prerequisites for the full target to RID table.
3. Configure the package
rootPackage is the Kotlin package the generated C# namespaces are rooted at; sub-packages map relative to it. See the nuget {} DSL reference for every field.
4. Pack it
packNuget runs KSP to generate the C# bindings, links the shared libraries for every configured target, and writes a real .nupkg at:
(the staged, unzipped contents sit alongside it at build/nuget/MyCatLib.1.0.0/). No .NET SDK is required for this step; see Prerequisites for what it does when one is present.
5. Consume it from C#
Point a C# project at the folder containing the .nupkg as a local NuGet feed and add a PackageReference. To publish to a real feed instead, run ./gradlew publishNuget; see Publish a Kotlin/Native library as NuGet. The package ships the native libs under runtimes/{rid}/native/ and the pre-generated Interop.cs under contentFiles/cs/<tfm>/, both wire up automatically, no consumer-side codegen.
For the mapping between individual Kotlin constructs and their generated C# shape, see Publishing Kotlin to C#.