Skip to content

Commit

Permalink
Added capability to detect the sql package in VS 17 (#1098)
Browse files Browse the repository at this point in the history
* Added capability to detect the sql package in VS 17

* updated the logic with vswhere
  • Loading branch information
chshrikh authored and ericsciple committed Jul 31, 2017
1 parent b63f950 commit aaa4106
Showing 1 changed file with 59 additions and 26 deletions.
85 changes: 59 additions & 26 deletions src/Misc/layoutbin/powershell/Add-SqlPackageCapabilities.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ function Get-MaxInfoFromSqlServerDtaf {
}
} |
Sort-Object -Descending
foreach ($version in $versions) {
foreach ($version in $versions) {
# Get the install directory.
$installDir = Get-RegistryValue -Hive 'LocalMachine' -View $view -KeyName "$dtafKeyName\$version" -Value 'InstallDir'
if (!$installDir) {
Expand All @@ -77,6 +77,25 @@ function Get-MaxInfoFromSqlServerDtaf {
}
}

function Get-MaxInfoFromVisualStudio_15_0 {
[CmdletBinding()]
param()

$vs15 = Get-VisualStudio_15_0
if ($vs15 -and $vs15.installationPath) {
# End with "\" for consistency with old ShellFolder values.
$shellFolder15 = $vs15.installationPath.TrimEnd('\'[0]) + "\"

# Test for the DAC directory.
$dacDirectory = [System.IO.Path]::Combine($shellFolder15, 'Common7', 'IDE', 'Extensions', 'Microsoft', 'SQLDB', 'DAC')
$sqlPacakgeInfo = Get-SqlPacakgeFromDacDirectory -dacDirectory $dacDirectory

if($sqlPacakgeInfo -and $sqlPacakgeInfo.File) {
return $sqlPacakgeInfo
}
}
}

function Get-MaxInfoFromVisualStudio {
[CmdletBinding()]
param()
Expand All @@ -102,35 +121,48 @@ function Get-MaxInfoFromVisualStudio {

# Test for the DAC directory.
$dacDirectory = [System.IO.Path]::Combine($installDir, 'Extensions', 'Microsoft', 'SQLDB', 'DAC')
if (!(Test-Container -LiteralPath $dacDirectory)) {
continue
$sqlPacakgeInfo = Get-SqlPacakgeFromDacDirectory -dacDirectory $dacDirectory

if($sqlPacakgeInfo -and $sqlPacakgeInfo.File)
{
return $sqlPacakgeInfo
}
}
}
}

# Get the DAC version folders.
$dacVersions =
Get-ChildItem -LiteralPath $dacDirectory |
Where-Object { $_ -is [System.IO.DirectoryInfo] }
# Filter to include integer key names only.
ForEach-Object {
$i = 0
if (([int]::TryParse($_.Name, [ref]$i))) {
$i
}
} |
Sort-Object -Descending
foreach ($dacVersion in $dacVersions) {
# Test for SqlPackage.exe.
$file = [System.IO.Path]::Combine($dacDirectory, $dacVersion, 'SqlPackage.exe')
if (!(Test-Leaf -LiteralPath $file)) {
continue
}
function Get-SqlPacakgeFromDacDirectory {
[CmdletBinding()]
param([string] $dacDirectory)

# Return the info as an object with properties (for sorting).
return New-Object psobject -Property @{
File = $file
Version = $dacVersion
}

if (!(Test-Container -LiteralPath $dacDirectory)) {
continue
}

# Get the DAC version folders.
$dacVersions =
Get-ChildItem -LiteralPath $dacDirectory |
Where-Object { $_ -is [System.IO.DirectoryInfo] }
# Filter to include integer key names only.
ForEach-Object {
$i = 0
if (([int]::TryParse($_.Name, [ref]$i))) {
$i
}
} |
Sort-Object -Descending
foreach ($dacVersion in $dacVersions) {
# Test for SqlPackage.exe.
$file = [System.IO.Path]::Combine($dacDirectory, $dacVersion, 'SqlPackage.exe')
if (!(Test-Leaf -LiteralPath $file)) {
continue
}

# Return the info as an object with properties (for sorting).
return New-Object psobject -Property @{
File = $file
Version = $dacVersion
}
}
}
Expand All @@ -139,6 +171,7 @@ $sqlPackageInfo = @( )
$sqlPackageInfo += (Get-MaxInfoFromSqlServer)
$sqlPackageInfo += (Get-MaxInfoFromSqlServerDtaf)
$sqlPackageInfo += (Get-MaxInfoFromVisualStudio)
$sqlPackageInfo += (Get-MaxInfoFromVisualStudio_15_0)
$sqlPackageInfo |
Sort-Object -Property Version -Descending |
Select -First 1 |
Expand Down

0 comments on commit aaa4106

Please sign in to comment.