Skip to content

Instantly share code, notes, and snippets.

@Aaronontheweb
Last active August 15, 2023 18:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Aaronontheweb/c141b47235fea226bc58ae5521407d82 to your computer and use it in GitHub Desktop.
Save Aaronontheweb/c141b47235fea226bc58ae5521407d82 to your computer and use it in GitHub Desktop.
Dacpac deploy script
# Define a parameter for the connection string
param (
[string]$ConnectionString = $null
)
# Step 1: Check if SqlPackage is installed, if not, install it
try {
SqlPackage
} catch {
Write-Host "SqlPackage is not installed, proceeding with the installation..."
dotnet tool install -g microsoft.sqlpackage
Write-Host "SqlPackage has been installed successfully."
}
# Step 2: Build the solution and create .dacpac files
Write-Host "Building the solution to generate .dacpac files..."
dotnet build -c Release
# Find all .dacpac files
$dacpacFiles = Get-ChildItem -Recurse -Filter *.dacpac
# Step 3: If connection string provided, publish the .dacpac files
if ($null -ne $ConnectionString -and $ConnectionString -ne '') {
foreach ($file in $dacpacFiles) {
Write-Host "Publishing $($file.FullName) to database..."
SqlPackage /a:Publish /sf:"$($file.FullName)" /tcs:"$ConnectionString"
}
} else {
Write-Host "No connection string provided, skipping publish step."
}
# Step 4: Completed
Write-Host "Script completed."
@Aaronontheweb
Copy link
Author

Removed logging of the connection string - did that while I was brushing up on my PowerShell knowledge

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment