我正在尝试使用 PowerShell 脚本在单个构建过程中部署多个 dacpac。
param(
[string]$publish_profile,
[string]$path_to_snapshots,
[string]$password
)
#Load Microsoft.SqlServer.Dac assembly
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.Dac")
#Load Dac profile
$dacProfile = [Microsoft.SqlServer.Dac.DacProfile]::Load($publish_profile)
$dacService = new-object Microsoft.SqlServer.Dac.DacServices($dacProfile.TargetConnectionString)
$files = Get-ChildItem "$path_to_snapshots\*.dacpac"
foreach ($file in $files)
{
$fileName = $file.Name
Try
{
$dp = [Microsoft.SqlServer.Dac.DacPackage]::Load($file.FullName)
$dacService.Deploy($dp, $database, $true)
}
}
Catch
{
Write-Host "$fileName deployment has been failed" -foregroundcolor "red"
throw $_.Exception;
Break
}
}
Run Code Online (Sandbox Code Playgroud)
在我的本地环境中,一切运行良好,但在 Visual Studio 团队服务的构建过程中,我收到错误:
2017-02-24T06:03:09.7955300Z *********.dacpac 部署失败
2017-02-24T06:03:09.9785258Z ##[error]使用“3”参数调用“Deploy”时发生异常(s):“无法部署包。”
在 D:\a\1\s********************\deploydatabase.ps1:104 char:13
+ $dacService.Deploy($dp, $database, $true)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ 类别信息:未指定: …
powershell dacpac azure-sql-database azure-devops azure-pipelines