Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Visual Studio 2015 build creates a dacpac file, but Azure Resource Manager templates can use only bacpac files.
This powershell script automates creation of bacpac and publishing to the blob storage.
After building the data project, open a command prompt on the folder containing the dacpac file.
Copy this script to the same folder.
You need :
1. Name of the localdb server where the dacpac is published ((localdb)\ProjectsV13)
2. Execute Get-AzurePublishSettingsFile and save the azure-account.publishsettings file in the same folder where dacpac file is located.
3. Storage Account Name
4. Storage Account Key.
To run this powershell script, open a command prompt and execute
powershell -noexit -File ".\create-bacpac.ps1"
# Publish DacPac to localdb
& "C:\Program Files (x86)\Microsoft SQL Server\130\DAC\bin\sqlpackage.exe" /Action:Publish /SourceFile:$DbName.dacpac /TargetDatabaseName:$DbName /TargetServerName:$ServerName
# Create BacPac from localdb
& "C:\Program Files (x86)\Microsoft SQL Server\130\DAC\bin\sqlpackage.exe" /a:Export /ssn:$ServerName /sdn:$DbName /tf:$BacPacFileName
# Copy BacPac to Azure Blob Storage
# 1. Execute Get-AzurePublishSettingsFile and save the publishsettings file.
# 2. Import publishsettings file
Import-AzurePublishSettingsFile $PubSettingsFile
# 3. Upload bacpac to blob storage
$context= New-AzureStorageContext -StorageAccountName $StorageAccountName -StorageAccountKey $StorageAccountKey
Set-AzureStorageBlobContent -Context $context -Container packages -File $BacPacFileName -Blob $BacPacFileName
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment