---
schema_version: "1"
id: 87432cd5110aab1a5b064a2487d8c5382f5de3ec34a906099a6eb372b715ed9b
title: Package Connected Apps in Second-Generation Managed Packaging
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/platform-pkg-exchange/managed_packaging/guides/second-generation/sfdx-dev-dev2gp-connected-app.md
canonical_url: https://developer.salesforce.com/docs/platform/pkg2-dev/guide/sfdx-dev-dev2gp-connected-app.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: 5d24b9497a830fd28a1b1f93bf74ac8c4972564622d08d956320ec1460b77627
products:
  - Second-Generation Managed Packaging Developer Guide
  - merged-docs
---

# Package Connected Apps in Second-Generation Managed Packaging

Add a connected app to a second-generation managed package.

## Before You Begin

**note:** Consider using External Client Apps instead. External Client Apps are the new and improved generation of connected apps. For details, see [Package External Client Apps In Second-Generation Managed Packages](https://help.salesforce.com/s/articleView?id=release-notes.rn_packaging_external_client_app.htm&release=250).

If the namespace for the connected app becomes corrupted, create an external client app to replace the connected app. External client apps can be packaged in [first-generation managed packages](https://help.salesforce.com/s/articleView?id=xcloud.package_external_client_app_with_1gp.htm) or [second-generation managed packages](https://help.salesforce.com/s/articleView?id=xcloud.configure_packageable_external_client_apps.htm).

Prerequisites: [Create a connected app](https://developer.salesforce.com/docs/atlas.en-us.sfdx_dev.meta/sfdx_dev/sfdx_dev_auth_connected_app.htm).

1.  Create a first-generation managed package (1GP) and add the connected app. It’s fine if the connected app is the only component in the package. Use the same namespace as the 2GP package for the 1GP package.

    Take note of the version number of the connected app; you’ll use this number later.

2.  From your packaging org, upload the 1GP package to create a package version.

3.  Promote the 1GP version to the released state.

    Promoting the 1GP version allows the connected app to be included in a second-generation managed package. You don’t need to install the 1GP version into an org.

4.  Navigate to the source for your connected app, or pull the source from the org where the connected app is being developed.

5.  Create a source `.xml` file in your 2GP directory and reference the connected app you want to include. See the _Sample Source File_ section.

6.  Create a second-generation managed package and add in the source code for the connected app. Add the source code manually. You can’t use `sf project retrieve start` or the `retrieve()` Metadata API call to add the source code.

## Sample Source File

```nolang
<ConnectedApp xmlns="http://soap.sforce.com/2006/04/metadata">
    <developerName>db_0110_ns4__A_Connected_App</developerName>
    <label>A Connected App</label>
    <version>1.0</version>
</ConnectedApp>

```

The developerName is the combination of your namespace (db_0110_ns4) and the name of your connected app (A_Connected_App).

The version specified in the source file is the version number of the connected app. Use decimal formatting when specifying the version number. The version number must match the version number of the connected app before it was added to the 1GP managed package.

**note:** When you add a connected app to a 1GP package, and upload the package, the version number of the connected app is auto incremented. For example, when version 4.0 of a connected app is added to a 1GP package, the package version increments the version number of the connected app from 4.0 to 5.0. When creating the source file for your 2GP package, specify the version number of the connected app before it was uploaded into a 1GP package, in this case, 4.0.
