Skip to content

Commit

Permalink
Correctly sort legacy instances if no setup helper
Browse files Browse the repository at this point in the history
Fixes issue #40 and adds tests to make sure we lexigraphically sort installationVersion when the ISetupHelper is not available (since as no VS2017 or newer instances available).
  • Loading branch information
heaths committed Mar 14, 2017
1 parent a6c20d3 commit 6c9abfa
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
35 changes: 35 additions & 0 deletions docker/Tests/legacy.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,39 @@ Describe 'vswhere -legacy' {
$instances.Count | Should Be 2
}
}

Context 'no instances' {
BeforeEach {
New-Item HKLM:\Software\WOW6432Node\Microsoft\VisualStudio\SxS\VS7 -Force | ForEach-Object {
foreach ($version in '10.0', '14.0') {
$_ | New-ItemProperty -Name $version -Value "C:\VisualStudio\$version" -Force
}
}

Start-Process -Wait -FilePath C:\Windows\SysWOW64\regsvr32.exe -ArgumentList @(
'/s',
'/u',
'C:\Downloads\Microsoft.VisualStudio.Setup.Configuration.Native\tools\x86\Microsoft.VisualStudio.Setup.Configuration.Native.dll'
)
}

AfterEach {
Start-Process -Wait -FilePath C:\Windows\SysWOW64\regsvr32.exe -ArgumentList @(
'/s',
'C:\Downloads\Microsoft.VisualStudio.Setup.Configuration.Native\tools\x86\Microsoft.VisualStudio.Setup.Configuration.Native.dll'
)
}

It 'returns 2 instances' {
$instances = C:\bin\vswhere.exe -legacy -format json | ConvertFrom-Json
$instances.Count | Should Be 2
}

It '-latest returns latest instance' {
$instances = C:\bin\vswhere.exe -legacy -latest -format json | ConvertFrom-Json
$instances.Count | Should Be 1
$instances[0].instanceId | Should Be 'VisualStudio.14.0'
$instances[0].installationPath | Should Be 'C:\VisualStudio\14.0'
}
}
}
7 changes: 6 additions & 1 deletion src/vswhere.lib/InstanceSelector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ InstanceSelector::InstanceSelector(_In_ const CommandArgs& args, _In_ ILegacyPro

bool InstanceSelector::Less(const ISetupInstancePtr& a, const ISetupInstancePtr& b) const
{
static ci_equal equal;
static ci_less less;

bstr_t bstrVersionA, bstrVersionB;
Expand Down Expand Up @@ -62,6 +61,12 @@ bool InstanceSelector::Less(const ISetupInstancePtr& a, const ISetupInstancePtr&
return SUCCEEDED(hrB);
}
}
else
{
// If ISetupHelper is not available we have only legacy products, or very early pre-releases of VS2017.
// For version 10.0 and newer either should lexigraphically sort correctly.
return less(wstring(bstrVersionA), wstring(bstrVersionB));
}
}
else
{
Expand Down

0 comments on commit 6c9abfa

Please sign in to comment.