Skip to content

Multi Framework Libraries

Justin Wojciechowski edited this page Aug 12, 2026 · 2 revisions

Multi-Framework Libraries

Some Swift vendors distribute their SDK as multiple interconnected frameworks. Stripe, for example, ships 14 frameworks — StripeCore, StripePayments, StripePaymentSheet, and so on — where higher-level modules import lower-level ones. This guide covers everything you need to bind these multi-framework libraries to .NET.

Single-framework library? If your library is a single xcframework with no Swift-level dependencies on other custom frameworks, the Getting Started guide is all you need. Come back here when you have two or more frameworks that depend on each other.

When You Need Multiple Binding Projects

The SDK supports one xcframework per binding project. If a vendor ships multiple frameworks, you create one binding project per framework.

Single-product libraries (Nuke, Lottie, Alamofire) need one project:

nuke-bindings/
└── SwiftBindings.Nuke.csproj

Multi-product vendors (Stripe, Firebase) need one project per public framework, grouped under a vendor directory:

payments-bindings/
├── PaymentsCore/
│   ├── SwiftBindings.Payments.Core.csproj
│   └── PaymentsCore.xcframework/
├── PaymentsAuth/
│   ├── SwiftBindings.Payments.Auth.csproj
│   └── PaymentsAuth.xcframework/
├── PaymentsUI/
│   ├── SwiftBindings.Payments.UI.csproj
│   └── PaymentsUI.xcframework/
└── PaymentsCrypto/          ← internal (ObjC-only), no csproj
    └── PaymentsCrypto.xcframework/

Rule of thumb: Create a vendor directory when there are 2+ frameworks from the same source repository, or when frameworks share a build step.


Dependency Mechanisms

Multi-framework bindings have two declaration mechanisms: ProjectReference for sibling binding projects, and SwiftFrameworkDependency for everything else (internal frameworks, external pre-built xcframeworks). The generator's module database is a third concept that almost never needs manual configuration — the SDK handles it automatically.

ProjectReference

Standard MSBuild project references between sibling binding projects. This is the only mechanism you need for sibling dependencies — the SDK wires each of the downstream build stages to the referenced project through the appropriate MSBuild hook, so the generator sees the sibling's source xcframework, the wrapper compiler sees the sibling's wrapper xcframework, and NuGet pack sees the sibling as a package dependency.

<!-- SwiftBindings.Payments.Auth.csproj -->
<ItemGroup>
  <ProjectReference Include="../PaymentsCore/SwiftBindings.Payments.Core.csproj" />
</ItemGroup>

What it does:

  • Generator cross-module type resolution — before the generator runs, the SDK scans each ProjectReference directory for *.xcframework and passes it as --framework-dependency. The generator parses the dependency's ABI JSON directly from the xcframework and loads its types in-memory, so cross-module parameters and return values resolve to their proper C# types instead of falling back to AnyType. No pre-built module database file is required — sibling xcframeworks are pre-built inputs that exist alongside the dependency csproj, so they are available on clean builds.
  • C# compilation — resolves types from the dependency binding project at compile time
  • Wrapper compilation — provides -F search paths so swiftc can find the dependency's wrapper xcframework (after the dependency project has built)
  • Native reference propagation — the dependency's source, wrapper, and bridge xcframeworks flow through GetNativeManifest to the consuming app bundle
  • NuGet packaging — dotnet pack converts ProjectReference to PackageReference, giving consumers transitive dependencies

For a sibling binding project, ProjectReference alone is sufficient. You do not need to duplicate the declaration with a <SwiftFrameworkDependency> item.

SwiftFrameworkDependency

Use SwiftFrameworkDependency for dependencies that have no sibling binding csproj to reference — internal frameworks (ObjC-only or binary-only helpers without public Swift API), and external pre-built xcframeworks that live outside the vendor directory. For sibling binding projects, prefer ProjectReference.

<!-- External / sibling package: native search path. Pair with a PackageReference. -->
<SwiftFrameworkDependency Include="path/to/External.xcframework"
                          PackageId="SwiftBindings.External"
                          PackageVersion="1.0.0" />
<PackageReference Include="SwiftBindings.External" Version="1.0.0" />

What it does:

  • Generator analysis — provides the xcframework path so the generator can parse its ABI JSON and resolve cross-module types
  • Wrapper compilation — adds -F search paths so swiftc can find the dependency module
  • Pack-time identity — PackageId and PackageVersion name the NuGet package that owns this xcframework so pack can validate the graph. They do not inject a <PackageReference>.

What it does NOT do:

  • Put the dependency's C# assembly on this project's compile
  • Auto-inject a <PackageReference> into this project or into the nupkg
  • Bundle the dependency xcframework into this package

The SFD is the native half; the PackageReference (or a <ProjectReference> for a sibling) is the managed half. Missing the managed ref is SWIFTBIND081 (CS0246 on a generated type name). A dependency that is genuinely native-only and whose types never reach the generated C# can opt out with NativeOnly="true".

PackageId and PackageVersion are required at pack time. Missing either is error SWIFTBIND040 — not a warning, and not suppressible. There is no "omit the metadata for internals" pack path. For an internal framework you do not publish, either give it its own small NuGet and reference that, or remove the SFD before pack and have consumers add a <NativeReference> (see below). Missing metadata is a pack-only check; a plain dotnet build still runs (the same SWIFTBIND040 code is reused for a different invariant — source dropped but no wrapper referenced — that does fail a regular build).

ModuleDatabase

The generator already produces a {Module}Database.xml alongside its generated output and, for local multi-framework builds, you almost never need to think about it. The generator resolves cross-module types by parsing each dependency's ABI JSON directly from the xcframework at generation time — no pre-built database file is required.

The database file matters only for NuGet package consumption: when a binding project depends on an upstream binding via PackageReference (not ProjectReference), the upstream's {Module}Database.xml ships inside the package under buildTransitive/ and is picked up automatically by the downstream generator. This is handled by the SDK — you don't need to configure anything.

Advanced escape hatches (rarely needed):

  1. ModuleDatabasePath on SwiftFrameworkDependency — point the generator at an explicit database file when the xcframework layout is non-standard
  2. <SwiftModuleDatabase> item — same as above, as a standalone item

When to Use Each

Scenario Mechanism
Sibling binding project (same solution) ProjectReference only
Internal framework (ObjC-only, no bindings) SwiftFrameworkDependency for build; exclude it before pack, or publish it as its own NuGet and reference that
External pre-built xcframework SwiftFrameworkDependency and matching PackageReference (both required)
NuGet package dependency PackageReference for restore + SwiftFrameworkDependency if this project also needs the xcframework at generation time

For sibling binding projects, ProjectReference alone is sufficient — the SDK auto-discovers the sibling xcframework and the generator handles cross-module type resolution on the first build.


Internal vs Public Dependencies

Vendor SDKs often include frameworks that are implementation details — ObjC-only helper libraries, internal utilities, or non-public modules that other public frameworks link against at runtime.

In the example above, PaymentsCrypto is an internal ObjC-only framework. It has no Swift module, so there's nothing to bind — but PaymentsAuth links against it at runtime.

Identifying internal frameworks

Internal frameworks typically:

  • Have no .swiftmodule directory (ObjC-only)
  • Are not documented as public API by the vendor
  • Are required at runtime by other public frameworks

Handling internal frameworks

Internal frameworks:

  • Do get an xcframework — they're needed for wrapper compilation search paths and at runtime
  • Do NOT get a binding project — there's no Swift API to bind
  • Are declared as SwiftFrameworkDependency — so the wrapper compiler can find them
<!-- SwiftBindings.Payments.Auth.csproj -->
<ItemGroup>
  <!-- Public dependency — use ProjectReference -->
  <ProjectReference Include="../PaymentsCore/SwiftBindings.Payments.Core.csproj" />

  <!-- Internal dependency — native search path for build. Either publish
       PaymentsCrypto as its own NuGet and add PackageId/PackageVersion + a
       PackageReference, or remove this item before `dotnet pack`
       (SWIFTBIND040). -->
  <SwiftFrameworkDependency Include="../PaymentsCrypto/PaymentsCrypto.xcframework"
                            NativeOnly="true" />
</ItemGroup>

NativeOnly="true" tells the SDK the item is not expected to contribute C# types (SWIFTBIND081 will not fire). It does not relax SWIFTBIND040: pack still needs PackageId/PackageVersion, or the item has to come out of the project before pack.

Only declare frameworks that your Swift module actually imports. Declaring unused dependencies won't break the build, but it clutters the build graph and slows generation. ObjC-only xcframeworks are a supported dependency kind — the generator detects them via the framework's module.modulemap, adds them to the wrapper compiler's -F search path, and simply skips them during Swift ABI parsing (since there's no Swift type surface to load). What the generator does reject is a xcframework that has neither a Swift .swiftmodule nor an ObjC module.modulemap — typically a Swift framework built without library evolution support, which should not be used as a binding dependency at all.

Runtime bundling of internal frameworks

Internal frameworks still need to be in the app bundle at runtime. Since SwiftFrameworkDependency does not bundle the dependency xcframework into the NuGet package, consumers must add internal frameworks as native references in their app project:

<!-- Consumer app project -->
<ItemGroup>
  <PackageReference Include="SwiftBindings.Payments.Auth" Version="2.0.0" />
  <NativeReference Include="path/to/PaymentsCrypto.xcframework">
    <Kind>Framework</Kind>
    <SmartLink>true</SmartLink>
  </NativeReference>
</ItemGroup>

For ProjectReference consumers (local development), internal frameworks propagate automatically via GetNativeManifest. The manual NativeReference is only needed by NuGet package consumers.


Two-Pass Build Pattern (wrapper compilation only)

Scope: This section is about Swift wrapper compilation ordering, not C# type resolution. Cross-module C# types are resolved on the first build via the generator's direct ABI parsing — no two-pass is needed for that. You may still encounter a two-pass requirement for wrapper compilation in specific scenarios described below.

Each binding project emits a Swift wrapper xcframework ({Module}SwiftBindings.xcframework) that the C# runtime calls into. Compiling a downstream module's wrapper (e.g., PaymentsAuth's) needs the upstream module's wrapper xcframework (e.g., PaymentsCore's) on the -F search path. If the upstream's wrapper doesn't exist yet, downstream wrapper compilation fails with SWIFTBIND051 ("no such module '…SwiftBindings'"). (SWIFTBIND050 is xcframework slicing — a missing platform slice in the source xcframework — and is a different failure.)

When a single pass is enough

When you build a downstream project with dotnet build PaymentsUI.csproj and PaymentsUI has ProjectReference items pointing at its upstream siblings, MSBuild recursively builds the upstream projects first (including their wrapper compile) before downstream wrapper compilation runs. This is the common case and completes in one invocation.

When a second pass is needed

You may still need a second pass when:

  • Projects are built individually in the wrong order. For example, dotnet build PaymentsUI.csproj before PaymentsCore has ever been built, with PaymentsCore declared only as a SwiftFrameworkDependency (no ProjectReference) — MSBuild has no reason to build PaymentsCore first, so its wrapper xcframework is missing.
  • A CI step builds each csproj one-at-a-time and tolerates failures. The SDK emits a hint message in this case suggesting a rebuild after upstream projects complete.
  • Wrapper output was cleaned while the downstream project's fingerprint is still valid. The fingerprint skip logic detects this and forces a wrapper-only recompile on the next build, which may need the upstream to be rebuilt too.

How to run a two-pass build

Build all projects twice, tolerating failures on the first pass:

# Pass 1: generate bindings and build whatever wrappers can be built
for project in PaymentsCore PaymentsAuth PaymentsUI; do
  dotnet build payments-bindings/$project/SwiftBindings.Payments.$project.csproj || true
done

# Pass 2: wrapper compilation succeeds (generation is skipped via fingerprint)
for project in PaymentsCore PaymentsAuth PaymentsUI; do
  dotnet build payments-bindings/$project/SwiftBindings.Payments.$project.csproj
done

Tip: If you declare sibling dependencies as ProjectReference, a single top-level dotnet build on the leaf-most consumer typically builds the whole graph in correct order in one shot — no two-pass needed.


Naming Conventions

Two naming patterns are common:

  • {Library}.Swift.iOS — used when binding your own library or a single third-party library. This is the default from dotnet new swift-binding (e.g., Nuke.Swift.iOS).
  • SwiftBindings.{Vendor}.{Module} — used for multi-product vendor SDKs where packages share a vendor prefix (e.g., SwiftBindings.Stripe.Core, SwiftBindings.Stripe.Payments). This is the convention used by the swift-dotnet-packages repo.

Both are valid. Choose based on whether you're publishing a single package or a family of related packages.


Complete Worked Example

This walkthrough binds a fictional "Payments" vendor SDK with four frameworks:

Framework Type Dependencies
PaymentsCore Public (Swift) None
PaymentsCrypto Internal (ObjC-only) None
PaymentsAuth Public (Swift) PaymentsCore, PaymentsCrypto
PaymentsUI Public (Swift) PaymentsCore, PaymentsAuth

Directory layout

payments-bindings/
├── PaymentsCore/
│   ├── SwiftBindings.Payments.Core.csproj
│   ├── PaymentsCore.xcframework/
│   └── README.md
├── PaymentsCrypto/
│   └── PaymentsCrypto.xcframework/     ← internal, no csproj
├── PaymentsAuth/
│   ├── SwiftBindings.Payments.Auth.csproj
│   ├── PaymentsAuth.xcframework/
│   └── README.md
└── PaymentsUI/
    ├── SwiftBindings.Payments.UI.csproj
    ├── PaymentsUI.xcframework/
    └── README.md

PaymentsCore (leaf module, no dependencies)

<!-- PaymentsCore/SwiftBindings.Payments.Core.csproj -->
<Project Sdk="SwiftBindings.Sdk">
  <PropertyGroup>
    <TargetFramework>net10.0-ios</TargetFramework>
    <PackageId>SwiftBindings.Payments.Core</PackageId>
    <Version>2.0.0</Version>
  </PropertyGroup>
</Project>

PaymentsAuth (depends on PaymentsCore + internal PaymentsCrypto)

Sibling public dependencies use ProjectReference. The internal ObjC-only PaymentsCrypto has no sibling csproj, so it stays as SwiftFrameworkDependency.

<!-- PaymentsAuth/SwiftBindings.Payments.Auth.csproj -->
<Project Sdk="SwiftBindings.Sdk">
  <PropertyGroup>
    <TargetFramework>net10.0-ios</TargetFramework>
    <PackageId>SwiftBindings.Payments.Auth</PackageId>
    <Version>2.0.0</Version>
  </PropertyGroup>

  <ItemGroup>
    <!-- Sibling public dep — xcframework auto-discovered from ../PaymentsCore/ -->
    <ProjectReference Include="../PaymentsCore/SwiftBindings.Payments.Core.csproj" />

    <!-- Internal ObjC-only: no sibling csproj, declare the xcframework directly -->
    <SwiftFrameworkDependency Include="../PaymentsCrypto/PaymentsCrypto.xcframework" />
  </ItemGroup>
</Project>

PaymentsUI (depends on PaymentsCore + PaymentsAuth)

<!-- PaymentsUI/SwiftBindings.Payments.UI.csproj -->
<Project Sdk="SwiftBindings.Sdk">
  <PropertyGroup>
    <TargetFramework>net10.0-ios</TargetFramework>
    <PackageId>SwiftBindings.Payments.UI</PackageId>
    <Version>2.0.0</Version>
  </PropertyGroup>

  <ItemGroup>
    <ProjectReference Include="../PaymentsCore/SwiftBindings.Payments.Core.csproj" />
    <ProjectReference Include="../PaymentsAuth/SwiftBindings.Payments.Auth.csproj" />

    <!-- PaymentsCrypto propagates transitively from PaymentsAuth's NativeReference,
         so PaymentsUI does not need to redeclare it. -->
  </ItemGroup>
</Project>

Build

A single dotnet build on the leaf-most consumer (PaymentsUI) builds the entire graph in the correct order via ProjectReference:

dotnet build PaymentsUI/SwiftBindings.Payments.UI.csproj

If you prefer to build projects individually, build upstream first so the wrapper xcframeworks are available when downstream wrapper compilation runs:

dotnet build PaymentsCore/SwiftBindings.Payments.Core.csproj
dotnet build PaymentsAuth/SwiftBindings.Payments.Auth.csproj
dotnet build PaymentsUI/SwiftBindings.Payments.UI.csproj

Packaging Considerations

Version coordination

All frameworks from the same vendor should use the same version number. Set <Version> explicitly in each .csproj rather than relying on auto-extraction, since xcframeworks often use Xcode's default placeholder version (SWIFTBIND020).

<PropertyGroup>
  <Version>2.0.0</Version>
</PropertyGroup>

How dotnet pack handles multi-framework deps

When you run dotnet pack on a project with <ProjectReference> items, MSBuild converts them to <PackageReference> entries in the .nuspec. Consumers who install SwiftBindings.Payments.UI automatically get SwiftBindings.Payments.Auth and SwiftBindings.Payments.Core as transitive dependencies.

<SwiftFrameworkDependency> does not inject <PackageReference> entries. Pack requires PackageId/PackageVersion on every SFD (SWIFTBIND040) and a matching <PackageReference> or <ProjectReference> on this project so NuGet restore actually pulls the dependency (SWIFTBIND081). Sibling ProjectReferences are converted to package dependencies by dotnet pack as usual.

Wrapper architectures

Before packing, ensure SwiftWrapperArchitectures is set to all (the default). If you overrode it to simulator during development, the pack will fail with SWIFTBIND030:

# Explicitly set for pack
dotnet pack -p:SwiftWrapperArchitectures=all

Pack order

Pack leaf dependencies first. While dotnet pack resolves project references locally, the resulting .nupkg files reference each other by PackageId and Version — so all versions must be consistent across the vendor.


Automatic Dependency Detection

The SDK can auto-detect framework dependencies by analyzing binary linkage. When SwiftAutoDetectDependencies is true (the default), the build:

  1. Parses the main xcframework's binary to find imported modules
  2. Searches for sibling binding projects matching those modules
  3. Auto-injects <ProjectReference> items for found siblings
  4. Emits SWIFTBIND080 warnings for unresolved dependencies with guidance on how to add them

This means a minimal .csproj with just <TargetFramework> can often build correctly — the SDK figures out the dependency graph. However, for complex vendors with internal frameworks, you'll typically need explicit <SwiftFrameworkDependency> items for the internal modules since they don't have sibling binding projects to auto-discover.

To disable auto-detection:

<PropertyGroup>
  <SwiftAutoDetectDependencies>false</SwiftAutoDetectDependencies>
</PropertyGroup>

Troubleshooting

Symptom Likely Cause Fix
SWIFTBIND051: "no such module 'PaymentsCoreSwiftBindings'" Missing wrapper xcframework on the search path (or the wrapper failed to compile) Add <ProjectReference> so MSBuild builds the upstream wrapper first, or declare the dependency xcframework as <SwiftFrameworkDependency>. SWIFTBIND050 is a different error — source xcframework slicing.
SWIFTBIND040 at pack An SFD is missing PackageId or PackageVersion Add both, plus a matching <PackageReference>, or remove the SFD before pack. Not a warning.
SWIFTBIND081 An SFD has a PackageId but no matching managed reference Add the <PackageReference> / <ProjectReference>, or mark the item NativeOnly="true" if no C# types from it can reach this binding.
SWIFTBIND060: types were skipped Generator couldn't resolve dependency types Ensure the dependency is declared (as ProjectReference for siblings, or SwiftFrameworkDependency for internal/external xcframeworks) — the generator resolves cross-module types automatically once the xcframework is on its dependency list
SWIFTBIND080: cross-module dependency detected Auto-detection found an import with no matching project Add <ProjectReference> (sibling project) or <SwiftFrameworkDependency> (external xcframework) as suggested in the warning
CS0246: type not found during C# compilation Missing <ProjectReference> to the project that defines the type Add <ProjectReference> to the dependency binding project
Generator error: "no Swift module and no ObjC module.modulemap" Declared SwiftFrameworkDependency is neither a Swift framework (with library evolution) nor an ObjC framework (with a modulemap) Remove the declaration — this xcframework can't be used as a generator input. Swift frameworks built without library evolution have no stable ABI and can't be bound; binary-only link-time helpers should be consumed as NativeReference in the app project instead.
Wrapper compiles on pass 2 but not pass 1 Upstream wrapper xcframework wasn't available when downstream wrapper compiled Use ProjectReference on upstream siblings so MSBuild builds them first in a single invocation; or build upstream projects first when building individually. See Two-Pass Build Pattern.

See Troubleshooting for the full error code reference.


Next Steps

Clone this wiki locally