Skip to content
This repository was archived by the owner on Jan 31, 2023. It is now read-only.

Conversation

@cmb69
Copy link
Contributor

@cmb69 cmb69 commented Apr 3, 2019

On systems where VS 2017 and VS 2019 are available, the starter script
may choose VS 2019 if vc15 is requested. The documentation on vswhere
isn't particularly clear regarding the -version parameter, but it
states that a version range is expected. Therefore we change the
shell setup script accordingly.

On systems where VS 2017 and VS 2019 are available, the starter script
may choose VS 2019 if vc15 is requested.  The documentation on vswhere
isn't particularly clear regarding the -version parameter, but it
states that a version range is expected.  Therefore we change the
shell setup script accordingly.
@cmb69
Copy link
Contributor Author

cmb69 commented Apr 3, 2019

Example session on my machine:

D:\php-sdk\bin>vswhere -nologo -version 15 -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath -format text
installationPath: C:\Program Files (x86)\Microsoft Visual Studio\2019\Community

installationPath: C:\Program Files (x86)\Microsoft Visual Studio\2017\Community

D:\php-sdk\bin>vswhere -nologo -version [15,16) -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath -format text
installationPath: C:\Program Files (x86)\Microsoft Visual Studio\2017\Community

set /a PHP_SDK_VS_RANGE=PHP_SDK_VS_NUM + 1
set PHP_SDK_VS_RANGE="[%PHP_SDK_VS_NUM%,!PHP_SDK_VS_RANGE%!)"

for /f "tokens=1* delims=: " %%a in ('%~dp0\vswhere -nologo -version !PHP_SDK_VS_RANGE! -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath -format text') do (
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great idea with the range. With this, the breaks are not needed in this loop, as it delivers just one result. Perhaps it would make sense to get rid of these breaks? The reason I rewrote it is that on my side the order was reversed - first 2017, then 2019. Now with your approach it seems to be consistent.

Thanks.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, yeah. I wonder what would happen if one has a preview and an RC installed side-by-side, though. In that case likely two installations will be found, i.e. two lines.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, preview is checked further down the line, attaching -prerelease to the command. Until vswhere changes behaviors, it should be ok.

Thanks.

These had been introduced to cater to multiple found VS installations,
to only use the first one.  Since the ranges are supposed to find only
a single installation, and since apparently the order of multiple
findings is not guaranteed, we remove the break constructs for better
readability of the source code.
@msftclas
Copy link

msftclas commented Apr 3, 2019

CLA assistant check
All CLA requirements met.

@weltling weltling merged commit 15cc209 into microsoft:master Apr 3, 2019
@cmb69 cmb69 deleted the vswhere-version-range branch April 3, 2019 14:15
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants