Skip to content

Commit

Permalink
Also search %PATH% for sqlpackage.exe
Browse files Browse the repository at this point in the history
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
  • Loading branch information
colind-work committed Mar 25, 2024
1 parent 5173c7a commit 8c6141f
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion d365fo.tools/internal/functions/invoke-sqlpackage.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down

0 comments on commit 8c6141f

Please sign in to comment.