Automating solution export/import

Loading

Automating solution export and import in Power Platform using the Power Platform CLI (PAC CLI) is a key part of modern DevOps and CI/CD practices. This guide will walk you step-by-step through setting up and executing the process using Application Users, ideal for secure, repeatable deployments across environments (e.g., Dev → Test → Prod).


What You’ll Learn

  • Setting up authentication with an Application User
  • Exporting a solution from a source environment
  • Importing a solution into a target environment
  • Handling managed/unmanaged solutions
  • Automating in pipelines (e.g., Azure DevOps, GitHub Actions)

Step-by-Step: Automating Solution Export/Import


1. Pre-requisites

Before automation, ensure:

  • You have Power Platform CLI installed (pac)
  • You’ve created an Application User with required roles (as discussed earlier)
  • You have:
    • Application (client) ID
    • Client secret
    • Tenant ID
    • Environment URLs (e.g., Dev and Prod)

2. Authenticate to Source Environment (Export)

Use your Application User credentials:

pac auth create --url https://<source-env>.crm.dynamics.com `
--applicationId <client-id> `
--clientSecret <client-secret> `
--tenant <tenant-id>

Check active authentication:

bashCopyEditpac auth list

Set the source environment as active:

pac auth select --index <index>

3. Export the Solution

Use the following command:

pac solution export --name "<solution_name>" `
--path "./exports/<solution_name>.zip" `
--managed true

Options:

  • --managed true → for Prod import
  • --managed false → for Dev environments
  • --targetVersion "1.0.0.2" → optional version control

Example:

pac solution export --name "MyApp" --path "./exports/MyApp.zip" --managed true

This exports the solution into a .zip file.


4. Authenticate to Target Environment (Import)

pac auth create --url https://<target-env>.crm.dynamics.com `
--applicationId <client-id> `
--clientSecret <client-secret> `
--tenant <tenant-id>

Select the environment:

pac auth select --index <target_index>

5. Import the Solution

pac solution import --path "./exports/MyApp.zip"

You can use flags like:

  • --publish-changes true
  • --overwrite-unmanaged-customizations true (use with caution)

Example:

pac solution import --path "./exports/MyApp.zip" --publish-changes true

6. Automating in Azure DevOps/GitHub Pipelines

Azure DevOps Example

steps:
- task: CmdLine@2
inputs:
script: |
pac auth create --url $(SourceEnvUrl) --applicationId $(AppId) --clientSecret $(AppSecret) --tenant $(TenantId)
pac solution export --name "$(SolutionName)" --path "$(Build.ArtifactStagingDirectory)/$(SolutionName).zip" --managed true

GitHub Actions Example

jobs:
export-import:
runs-on: windows-latest
steps:
- name: Setup PAC CLI
run: |
dotnet tool install --global Microsoft.PowerApps.CLI.Tool
- name: Authenticate & Export
run: |
pac auth create --url ${{ secrets.SOURCE_ENV_URL }} --applicationId ${{ secrets.APP_ID }} --clientSecret ${{ secrets.APP_SECRET }} --tenant ${{ secrets.TENANT_ID }}
pac solution export --name "MyApp" --path "./MyApp.zip" --managed true

7. Optional: Convert to Managed/Unmanaged

You can also convert solutions manually before deployment:

pac solution pack --zipFile "./MyApp.zip" --folder "./MyAppSrc" --packagetype Managed

8. Best Practices

  • Keep your solution version updated
  • Export from unmanaged (Dev) → import as managed (Test/Prod)
  • Store secrets in Azure Key Vault or GitHub Secrets
  • Log exports/imports for auditing

9. Troubleshooting Tips

IssueResolution
Invalid client credentialsDouble-check secret, client ID, and tenant
Solution not foundMake sure solution name matches exactly
Import failedEnsure all required components (e.g., tables, flows) exist in target
Access deniedCheck if App User has necessary security role (System Administrator or custom)

Leave a Reply

Your email address will not be published. Required fields are marked *