09 October 2025

💡 How to Import a Bacpac File into a Cloud-Hosted D365 F&O Environment

When working with a newly deployed cloud-hosted Dynamics 365 Finance & Operations (D365 F&O) environment, you might want to populate it with data from a .bacpac file—typically exported from a sandbox or UAT environment.

There are several ways to do this, and unfortunately, quite a few things can go wrong along the way. My preferred method is using the d365fo.tools PowerShell module, which simplifies the process of repairing and importing .bacpac files.

🛠 Step 1: Install d365fo.tools

Start by installing the required PowerShell modules:

Install-PackageProvider nuget -Scope AllUsers -Force -Confirm:$false

Install-Module -Name d365fo.tools -AllowClobber -Scope AllUsers -Force -Confirm:$false

⚠️ Troubleshooting Installation Issues

If you encounter the following error:

PackageManagement\Install-Package : No match was found for the specified search criteria and module name 'd365fo.tools'. Try Get-PSRepository to see all available registered module repositories.

You’ll need to register the default repository manually:

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12

Register-PSRepository -Default -Verbose

Verify the repository registration:

Get-PSRepository

🔧 Step 2: Repair the Bacpac File (if needed)

Sometimes the .bacpac file needs to be repaired before it can be imported:

Repair-D365BacpacModelFile -Path "D:\UAT.bacpac" -Verbose

📥 Step 3: Import the Bacpac File

Once repaired (or if the original file is fine), import it into your environment:

Import-D365Bacpac -ImportModeTier1 -BacpacFile "D:\UAT.bacpac" -NewDatabaseName "AXDB_import" -Verbose

🔄 Step 4: Switch Databases and Sync

After importing, you’ll need to stop the environment, switch the active database, perform a DB sync, and restart everything:

Stop-D365Environment -All

Switch-D365ActiveDatabase -SourceDatabaseName AXDB_import

Invoke-D365DBSync -ShowOriginalProgress

Start-D365Environment -All