Last active
August 15, 2023 18:05
-
-
Save Aaronontheweb/c141b47235fea226bc58ae5521407d82 to your computer and use it in GitHub Desktop.
Dacpac deploy script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Removed logging of the connection string - did that while I was brushing up on my PowerShell knowledge