Bind a NuGet package for Kotlin
Select a C# API from a NuGet dependency, generate Kotlin bindings, and package the bridge with MyCatLib so a .NET consumer can call through Kotlin to the bound package.
This guide continues the MyCatLib project from Publish a Kotlin/Native library as NuGet.
1. Select the package and C# namespaces
Add a dependency with bind {}. This example binds only the MimeMapping namespace and places its generated Kotlin API in the mimemapping package:
2. Generate the bindings
Run the IDE-sync umbrella task:
The task restores the package, reads its public assembly metadata, and generates Kotlin stubs plus C# registration shims. The Kotlin output is added to nativeMain, so regular source can import it. Add this helper under src/nativeMain/kotlin/com/example/cats/mime/MimeSample.kt:
3. Package the bridge and call it
Run packNuget again. When both publish {} and dependencies {} are present, the package includes the C# registration shims and an exact dependency on the bound NuGet package. The .NET consumer still references only the Kotlin library package.
The helper is exported from Kotlin under the MyCatLib.Mime namespace, completing a C# to Kotlin to bound NuGet round trip:
If a generated binding reports that registrations did not fire, follow Registration diagnostics. For the generated pipeline and supported C# member shapes, continue with Consuming C# in Kotlin.