Skip to content

Publishing

Justin Wojciechowski edited this page Nov 30, 2026 · 12 revisions

Publishing

This guide covers packaging your Swift binding projects into NuGet packages and publishing them for consumption. The Swift Bindings SDK / Runtime / Templates packages themselves are released from the generator repo (release/sdk-X.Y.Z branches, nuke pack, then dotnet nuget push) — that pipeline is not this page.

Package Contents

When you run dotnet pack on a binding project, the SDK produces a .nupkg containing everything consumers need:

Contents NuGet Path Purpose
C# bindings DLL lib/net10.0-ios26.0/ Managed assembly with P/Invoke declarations and type wrappers
ObjC companion DLL (mixed frameworks only) lib/net10.0-ios26.0/ bgen-compiled managed binding for the framework's Objective-C surface, embedded automatically so a single PackageReference delivers both the Swift and ObjC APIs (no separate companion package)
Source xcframework native/net10.0-ios26.0/MyLibrary.xcframework/ Original Swift library (device + simulator slices)
Wrapper xcframework native/net10.0-ios26.0/MyLibrarySwiftBindings.xcframework/ Compiled Swift wrapper (async, constructors, protocol dispatch)
Bridge xcframework native/net10.0-ios26.0/MyLibraryBridge.xcframework/ SwiftUI bridge (only present if SwiftUI views were detected)
Module database buildTransitive/net10.0-ios26.0/MyLibraryDatabase.xml Cross-module type resolution for downstream binding projects
Consumer .targets buildTransitive/net10.0-ios26.0/MyLibrary.Swift.iOS.targets Injects NativeReference items for that copy's native/ frameworks, so consumers get them automatically
Copy declaration buildTransitive/net10.0-ios26.0/MyLibrary.Swift.iOS.props Records the toolchain this copy was built on so the consuming app's build can check it

The subfolder under lib/, buildTransitive/, and native/ uses the binding's target framework as labeled by the workload. A versionless net10.0-ios binding packs as net10.0-ios26.0 on every .NET 10 workload, a binding pinned to a platform version (for example, an Apple-framework binding on net10.0-ios27.2) packs under that version, and a net11.0-ios binding packs as net11.0-ios27.2. See Choosing .NET and Xcode. The 3 folders for a target framework make up one copy of the binding. A package from a single dotnet pack holds one copy per platform, while a merged package holds one per toolchain (see One package for every toolchain).

Native frameworks are not split by runtime identifier, and nothing ships under runtimes/. An x86_64 consumer (iossimulator-x64, osx-x64, …) uses the same native/ folder. When the source xcframework includes an x86_64 slice, the wrapper is a fat arm64+x86_64 binary.

Two pack shapes differ from the table above:

  • Static source + wrapper. If the source library is a static archive and a wrapper was produced, the source xcframework is dropped from the nupkg (the wrapper is the sole native carrier) so the ObjC runtime does not register the same class twice.
  • Pure Objective-C. The native framework ships as lib/<tfm>/{Assembly}.resources[.zip]. There is no native/ folder and no buildTransitive consumer .targets (SWIFTBIND074 if it is missing).

Required Metadata

Three properties matter for packaging:

<PropertyGroup>
  <PackageId>MyLibrary.Swift.iOS</PackageId>
  <PackageVersion>2.5.0</PackageVersion>
  <Description>Swift bindings for MyLibrary</Description>
</PropertyGroup>
  • PackageId defaults to the project name. The generator uses this for the consumer .targets filename, so it must match across build and pack.
  • PackageVersion is auto-extracted from the xcframework's Info.plist (CFBundleShortVersionString). If the framework uses Xcode's default "1.0" placeholder, you'll see SWIFTBIND020 — set <PackageVersion> explicitly.
  • Description, Authors, PackageLicenseExpression, and other standard NuGet metadata follow normal MSBuild conventions. For multi-package repos, centralize shared metadata in a Directory.Build.props:
<!-- Directory.Build.props -->
<Project>
  <PropertyGroup>
    <Authors>Your Name</Authors>
    <PackageLicenseExpression>MIT</PackageLicenseExpression>
    <PackageProjectUrl>https://github.com/yourorg/your-packages</PackageProjectUrl>
    <PackageTags>swift;dotnet;interop;bindings</PackageTags>
  </PropertyGroup>
</Project>

See Customization for the full list of packaging properties.


Pre-Pack Validation

The SDK runs validation checks before packing. These are the common blockers:

SWIFTBIND030 — Wrapper architectures

NuGet packages must include both device and simulator slices. If SwiftWrapperArchitectures is set to simulator (common during development for faster builds), pack will fail:

error SWIFTBIND030: NuGet packages require both device and simulator wrapper slices.

Fix by removing the override or setting it to all:

<PropertyGroup>
  <SwiftWrapperArchitectures>all</SwiftWrapperArchitectures>
</PropertyGroup>

Or pass it on the command line:

dotnet pack -p:SwiftWrapperArchitectures=all

SWIFTBIND031 — Missing slices

The source xcframework itself must contain both device and simulator slices. If it only has one (e.g., built with xcodebuild for a single destination), pack will fail:

error SWIFTBIND031: Wrapper xcframework is missing device or simulator slice.

Rebuild the xcframework with both slices. See Getting Started — Building an xcframework from SPM.

SWIFTBIND035 — Platform version resolution

If the TargetFramework is versionless (e.g., net10.0-ios) and no platform workload is installed, the SDK can't resolve the version needed for NuGet pack paths:

error SWIFTBIND035: Cannot resolve platform version for NuGet pack.

Install the platform workload (dotnet workload install ios) or use a versioned TFM that your workload installs (net10.0-ios26.0 works on every .NET 10 workload; net11.0-ios27.2 on .NET 11). See Choosing .NET and Xcode.

SWIFTBIND040 — Dependency metadata

Every <SwiftFrameworkDependency> needs PackageId and PackageVersion. Missing either is a pack-time error, not a warning:

error SWIFTBIND040: SwiftFrameworkDependency 'Dep.xcframework' is missing PackageId or PackageVersion metadata.

That metadata identifies the NuGet package that owns the xcframework. It does not inject a <PackageReference> — add the matching one yourself (or a <ProjectReference> for a sibling) so restore actually pulls the dependency. See SWIFTBIND081 if you set the metadata and still get CS0246 on a generated type.

<SwiftFrameworkDependency Include="../Dep.xcframework"
                          PackageId="Dep.Swift.iOS"
                          PackageVersion="1.0.0" />
<PackageReference Include="Dep.Swift.iOS" Version="1.0.0" />

For an internal framework you do not publish as its own NuGet, remove the SFD before pack (or give it a package). There is no "omit the metadata and suppress a warning" path. Consumers then add a <NativeReference> for that xcframework. See Multi-Framework Libraries — Internal vs Public Dependencies.


Local Testing

Before publishing, test the package in a consuming app.

1. Set up a local NuGet source

Create a directory for local packages and configure NuGet to use it:

mkdir -p local-packages

Add a NuGet.config at the solution root:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <clear />
    <add key="local" value="local-packages" />
    <add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
  </packageSources>
</configuration>

The <clear /> ensures only your declared sources are used, preventing stale cached versions from nuget.org.

2. Pack into the local source

dotnet pack -c Release /p:Version=1.0.0-preview.1 -o local-packages/

3. Reference from a consuming app

<PackageReference Include="MyLibrary.Swift.iOS" Version="1.0.0-preview.1" />
dotnet build
dotnet run   # or deploy to simulator/device

4. Iterate

When iterating on the package, increment the prerelease version (e.g., preview.2, preview.3) or clear the NuGet cache to pick up changes:

dotnet nuget locals all --clear

Multi-Framework Packages

When a Swift vendor SDK has multiple frameworks (e.g., a core library plus feature modules), each framework gets its own binding project and NuGet package. Coordination matters:

Version alignment

All packages from the same vendor should use the same version number. Set the version once in Directory.Build.props or pass it on the command line:

dotnet pack -c Release /p:Version=2.5.0

Build and pack order

Dependencies must be built before dependents. If FeatureModule imports CoreLibrary, build and pack CoreLibrary first so that FeatureModule can resolve its dependency during wrapper compilation.

For multi-pass builds where wrapper compilation depends on sibling projects, build all projects once (tolerating wrapper failures), then build again so deferred wrapper compilation succeeds:

# Pass 1: generate bindings, compile wrappers where possible
dotnet build CoreLibrary.Swift.iOS -c Release
dotnet build FeatureModule.Swift.iOS -c Release || true

# Pass 2: deferred wrapper compilation succeeds
dotnet build FeatureModule.Swift.iOS -c Release

# Pack in dependency order
dotnet pack CoreLibrary.Swift.iOS --no-build -c Release /p:Version=2.5.0 -o packages/
dotnet pack FeatureModule.Swift.iOS --no-build -c Release /p:Version=2.5.0 -o packages/

Dependency declaration

Use <ProjectReference> alone for sibling binding projects in the same solution — the SDK auto-discovers the sibling's xcframework and wires it through the generator, wrapper compiler, and dotnet pack (transitive <PackageReference>) automatically. Use <SwiftFrameworkDependency> with PackageId and PackageVersion for external pre-built xcframeworks (and without metadata for internal helpers that won't be published). See Multi-Framework Libraries for the full dependency guide.


One package for every toolchain

A package from one dotnet pack carries the copy built on that pairing. A .NET 10 + Xcode 27.2 app or a .NET 11 app can use a .NET 10 + Xcode 26.3 copy, but then it gets that older copy's API and native frameworks. A .NET 10 app can't restore a .NET 11 copy at all. To serve all 3 pairings from one package version, pack one contribution on each pairing and merge the contributions. The merged package carries one copy per pairing, and each app gets the copy built for its toolchain.

1. Pack one contribution per pairing

Every contribution must come from the same source, with the same package ID, version, and metadata, and the same SwiftBindings.Sdk version. Each pairing packs its own explicitly versioned target frameworks:

Pairing iOS copy Other platforms
.NET 10 + Xcode 26.3 net10.0-ios26.0 net10.0-maccatalyst26.0, net10.0-macos26.0, net10.0-tvos26.0
.NET 10 + Xcode 27.2 net10.0-ios27.2 net10.0-maccatalyst27.2, …
.NET 11 + Xcode 27.2 net11.0-ios27.2 net11.0-maccatalyst27.2, …

Label the oldest copy 26.0, not 26.2. A versionless net10.0-ios class library restores the 26.0 platform on every .NET 10 workload, so a package whose oldest copy is newer fails to restore with NU1202. On .NET 10 + Xcode 27.2, specify 27.2 explicitly. A versionless project there still packs as 26.0, which conflicts with the Xcode 26.3 copy, and an Apple-framework binding refuses to pack that way (SWIFTBIND137).

Let each pairing pass its own list by storing the target frameworks in a custom property instead of <TargetFramework>:

<PropertyGroup>
  <BindingTargetFrameworks Condition="'$(BindingTargetFrameworks)' == ''">net10.0-ios</BindingTargetFrameworks>
  <TargetFrameworks>$(BindingTargetFrameworks)</TargetFrameworks>
</PropertyGroup>

Run each pack on its pairing, in its own CI job or checkout with that pairing's global.json and Xcode (see Choosing .NET and Xcode). Start from a clean bin/ and obj/:

# .NET 10 + Xcode 26.3
dotnet pack -c Release -p:BindingTargetFrameworks=net10.0-ios26.0 -p:Version=2.5.0 -o contributions/net10-xcode26
# .NET 10 + Xcode 27.2
dotnet pack -c Release -p:BindingTargetFrameworks=net10.0-ios27.2 -p:Version=2.5.0 -o contributions/net10-xcode27
# .NET 11 + Xcode 27.2
dotnet pack -c Release -p:BindingTargetFrameworks=net11.0-ios27.2 -p:Version=2.5.0 -o contributions/net11-xcode27

For more than one platform, quote the list: '-p:BindingTargetFrameworks="net10.0-ios26.0;net10.0-maccatalyst26.0"'. Don't sign the contributions. The merge refuses signed packages, so sign the merged package instead.

2. Merge the contributions

Run the merge from the binding project. This example runs it on .NET 10 + Xcode 26.3, with that pairing's target framework:

dotnet msbuild MyLibrary.Swift.iOS.csproj -restore -t:SwiftBindingsMergePackages \
  -p:BindingTargetFrameworks=net10.0-ios26.0 \
  '-p:SwiftBindingsMergeContributions="contributions/net10-xcode26/MyLibrary.Swift.iOS.2.5.0.nupkg;contributions/net10-xcode27/MyLibrary.Swift.iOS.2.5.0.nupkg;contributions/net11-xcode27/MyLibrary.Swift.iOS.2.5.0.nupkg"' \
  '-p:SwiftBindingsMergeTargetFrameworks="net10.0-ios26.0;net10.0-ios27.2;net11.0-ios27.2"' \
  -p:SwiftBindingsMergeOutput=packages

The inner double quotes keep MSBuild from splitting the lists at their semicolons, and the outer single quotes keep the shell from removing them. SwiftBindingsMergeTargetFrameworks is the full list of copies the merged package must carry, and the contributions must carry each one exactly once. The merge writes MyLibrary.Swift.iOS.2.5.0.nupkg to SwiftBindingsMergeOutput (by default the project's PackageOutputPath). That directory must not hold one of the contributions, since the merged package has the same file name. If the binding has a ProjectReference, the merge reads that project's build output in the pack configuration (Release by default, or $(Configuration) when PackRelease is false). Set -p:SwiftBindingsMergeConfiguration=<name> if you packed the contributions in another configuration.

The merge fails with SWIFTBIND138 when the contributions don't match as a single package, and its message says what differs. The merge also checks that each newer copy keeps everything an older copy of the same platform offers. That covers every public type and member, every native export, the value of every constant and default parameter, and the Swift declaration behind every C# name. A class library compiles against the oldest copy, while the app that uses the library runs its own newer copy, so anything a newer copy drops or changes would break that library at run time. The SDK also checks the merged package the same way a consuming app's build checks a binding (SWIFTBIND132) and fails with SWIFTBIND133 if an app would refuse it. A path inside the package that is too long for a Visual Studio restore on Windows is a warning (SWIFTBIND140). Set -p:SwiftBindingsMergeRequireWindowsPathBudget=true to make it an error.

3. How an app picks its copy

NuGet selects the nearest target framework the package carries, with no configuration needed from the consumer:

Consumer Copy
net10.0-ios app on .NET 10 + Xcode 26.3 net10.0-ios26.0
net10.0-ios app on .NET 10 + Xcode 27.2 net10.0-ios27.2
net11.0-ios app on .NET 11 + Xcode 27.2 net11.0-ios27.2
versionless net10.0-ios class library net10.0-ios26.0 to compile against. The app that references the library still embeds its own copy.

The build log shows the copy resolved for each package, for example SwiftBindings copy: MyLibrary.Swift.iOS 2.5.0 -> net10.0-ios27.2 (built on …). When a package has no copy for the app's toolchain, the app uses the nearest older copy and the build reports SWIFTBIND139 as a message. For example, this happens when a .NET 11 app references a package with only .NET 10 copies. To make that an error, set:

<PropertyGroup>
  <SwiftBindingsRequireExactCopy>true</SwiftBindingsRequireExactCopy>
</PropertyGroup>

If the build resolves the binding assembly from one copy and the consumer targets from another, it fails with SWIFTBIND136 rather than linking one toolchain's native frameworks with another toolchain's assembly. Restore again. If the error persists, the package is malformed: repack it with the current SDK or merge it with SwiftBindingsMergePackages.


Publishing to NuGet.org

Push packages

dotnet nuget push packages/MyLibrary.Swift.iOS.1.0.0.nupkg \
  --source https://api.nuget.org/v3/index.json \
  --api-key YOUR_API_KEY \
  --skip-duplicate

The --skip-duplicate flag prevents errors when re-pushing an already-published version (useful in CI retries).

API key setup

  1. Go to nuget.org/account/apikeys
  2. Create a key scoped to your package ID pattern (e.g., SwiftBindings.* for the official packages, or YourPrefix.* for your own)
  3. Store the key as a CI secret — never commit it to source control

Publish multiple packages

When publishing a multi-framework set, push in dependency order:

for pkg in packages/*.nupkg; do
  dotnet nuget push "$pkg" \
    --source https://api.nuget.org/v3/index.json \
    --api-key "$NUGET_API_KEY" \
    --skip-duplicate
done

CI/CD Automation

For automated releases, the recommended pattern is tag-based triggering: pushing a Git tag like MyLibrary/1.0.0 triggers a CI workflow that builds, tests, packs, and publishes.

Release workflow pattern

  1. Parse the tag to extract the library name and version (e.g., MyLibrary/1.0.0 -> library=MyLibrary, version=1.0.0)
  2. Build xcframeworks from source (or fetch prebuilt ones)
  3. Build the binding projects (dotnet build -c Release) — the SDK generates bindings and compiles wrappers automatically
  4. Run tests on iOS Simulator to validate the bindings work at runtime
  5. Pack each project in dependency order (dotnet pack --no-build -c Release /p:Version=1.0.0)
  6. Publish to NuGet.org with --skip-duplicate

Dry-run mode

Support a dry_run flag (via workflow_dispatch input) that runs steps 1-5 without publishing. This lets you verify the full pipeline before cutting a real release.

Reference implementation

The swift-dotnet-packages repository has a working release.yml GitHub Actions workflow that implements this pattern, including multi-pass builds for complex dependency graphs, simulator test validation, and artifact archiving. Use it as a starting point for your own CI.


Consumer Experience

When a consumer installs a Swift binding NuGet package, everything works automatically:

<PackageReference Include="MyLibrary.Swift.iOS" Version="1.0.0" />

The consumer .targets file in the package handles the rest:

  • Native framework bundling — The source xcframework, wrapper xcframework, and bridge xcframework (if present) are injected as NativeReference items. The .NET build system bundles them into the app automatically.
  • Module database propagation — If the consumer is itself a binding project, the module database XML enables cross-module type resolution.
  • Platform version validation — The .targets file warns (SWIFTBIND011) if the consumer's SupportedOSPlatformVersion is lower than what the framework requires.
  • NativeAOT compatibility — The SwiftBindingsInteropMode property auto-detects NativeAOT builds and adjusts calling convention behavior. See NativeAOT Deployment for details.

Consumers don't need the Swift Bindings SDK, generator, or any Swift expertise. They do still need the standard .NET iOS/macOS build toolchain (Xcode, .NET SDK with platform workloads) to build and deploy their app — but the Swift interop layer is fully handled by the NuGet package.


App Store submission and native packaging

A Swift-binding app submitted to the App Store has to satisfy Apple's native-packaging rules. The packages are built so a finished .ipa is compliant out of the box — there is nothing extra to configure.

The runtime ships as a signed framework, never a loose dylib

SwiftBindings.Runtime packages its native helper as SwiftBindingsRuntime.xcframework (device + simulator framework slices). When you build an app, it embeds as a signed Frameworks/SwiftBindingsRuntime.framework/SwiftBindingsRuntime with install name @rpath/SwiftBindingsRuntime.framework/SwiftBindingsRuntime. A loose Frameworks/lib*.dylib (anything other than Apple's own /usr/lib/swift libswift*) is rejected at submission, so the runtime is never shipped as a bare dylib.

No SwiftSupport/ folder, no bundled libswift*.dylib

Bindings target the stable Swift ABI with a minimum of iOS 15, so the app links the Swift runtime that already ships in the OS at /usr/lib/swift. That means a compliant .ipa:

  • embeds zero libswift*.dylib (the Swift standard library is resolved from the OS, not copied into the app),
  • has no top-level SwiftSupport/ folder, and
  • carries no loose runtime dylib in Frameworks/.

This is what fixes the historical ITMS-90426 "Invalid Swift Support — the SwiftSupport folder is missing" rejection (issue #42): there is no SwiftSupport/-folder injector because a stable-ABI min-iOS-15 app does not need one. See Apple Technical Note TN2435.

If you previously worked around the rejection by hand-adding a SwiftSupport/ folder or a loose dylib, remove that step — it is now both unnecessary and a submission risk.

Hitting ITMS-90426 today? See Troubleshooting — App Store: "The SwiftSupport folder is missing".

macOS and Mac Catalyst: embedded frameworks are rewritten to the versioned layout

Apple expects the opposite bundle shape on either side of the platform line. An iOS or tvOS framework must be shallow — the binary and Info.plist at the bundle root. A macOS or Mac Catalyst framework must be versioned: a root holding only Versions/ plus symlinks, the binary at Versions/A/<Name>, and the plist at Versions/A/Resources/Info.plist. dyld loads either shape on macOS, so a framework authored in the iOS shape runs fine everywhere and only reads as malformed when a Mac app is validated for the store (ITMS-90291 / ITMS-90292). Every xcframework slice these packages ship — the runtime, the Apple supplements, a binding's wrapper — is authored in the shallow shape, which is correct and required on iOS.

The versioned shape needs real symlinks, and a NuGet package is a zip that does not round-trip them. So since SwiftBindings.Runtime 0.19.1 the rewrite happens on your Mac, inside the app bundle Apple actually validates: a buildTransitive step converts every framework in Contents/Frameworks/ (ours, a vendor's, anything the build embedded) after the workload has copied and post-processed them and before codesign seals the bundle. It is idempotent, so an incremental rebuild finds the shape already correct and does nothing.

Because the step rides on SwiftBindings.Runtime, which every Swift and mixed binding package depends on, a binding package published before 0.19.1 picks it up when the consuming app resolves the newer runtime — nothing needs to be re-packed. An app that opts out of the implicit runtime reference (DisableImplicitSwiftRuntimeReference) gets the same step from the SDK instead.

It runs only for a macos / maccatalyst target framework on a Mac build host. iOS and tvOS apps are untouched. A build that embedded frameworks into a Mac app bundle but never ran the step fails with SWIFTBIND082 rather than silently shipping the wrong anatomy. Two escape hatches exist for the rare case that needs them — see Customization — SwiftBindingsDeepenMacFrameworks.

Rejected with ITMS-90291 / ITMS-90292 today? See Troubleshooting — App Store: malformed framework bundle on macOS / Mac Catalyst.


Next Steps

Clone this wiki locally