From 8c6141f594a2a7566e9abf6ca144939db051aafd Mon Sep 17 00:00:00 2001 From: Colin Daley Date: Mon, 25 Mar 2024 01:32:04 +0000 Subject: [PATCH] Also search %PATH% for sqlpackage.exe The installation documentation for SqlPackage says: Installing SqlPackage as a global tool makes it available on your path as sqlpackage and is the recommended method to install SqlPackage for Windows, macOS, and Linux. In line with Microsoft's expectations, also search %PATH% if sqlpackage is not found in the d365fo.tools default path ($Script:SqlPackagePath). If it is found in the %PATH% then update the default path with the actual path to sqlpackage.exe. Author: Colin Daley Date: 2024-03-24 --- .../internal/functions/invoke-sqlpackage.ps1 | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/d365fo.tools/internal/functions/invoke-sqlpackage.ps1 b/d365fo.tools/internal/functions/invoke-sqlpackage.ps1 index 4d340d53..9c2a9b3f 100644 --- a/d365fo.tools/internal/functions/invoke-sqlpackage.ps1 +++ b/d365fo.tools/internal/functions/invoke-sqlpackage.ps1 @@ -133,7 +133,22 @@ function Invoke-SqlPackage { Invoke-TimeSignal -Start - if (!(Test-PathExists -Path $executable -Type Leaf)) { return } + if (!(Test-PathExists -Path $executable -Type Leaf)){ + try{ + $envSqlPackage = (Get-Command -Name "sqlpackage.exe").Source + if (!(Test-PathExists -Path $envSqlPackage -Type Leaf)) { return } + else{ + $executable = $envSqlPackage + Set-D365SqlPackagePath -Path $executable + } + } + catch + { + # SqlPackage.exe is not in $Script:SqlPackagePath + # and not in %PATH%, so + return + } + } Write-PSFMessage -Level Verbose -Message "Starting to prepare the parameters for sqlpackage.exe"