Skip to content

Commit

Permalink
utils.pwsh: Update Visual Studio detection to use VSSetup module
Browse files Browse the repository at this point in the history
  • Loading branch information
PatTheMav committed Jun 17, 2023
1 parent effe385 commit 40bc0c0
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 25 deletions.
3 changes: 2 additions & 1 deletion Build-Dependencies.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ param(
[switch] $SkipAll,
[switch] $SkipBuild,
[switch] $SkipDeps,
[switch] $SkipUnpack
[switch] $SkipUnpack,
[switch] $VSPrerelease
)

$ErrorActionPreference = "Stop"
Expand Down
4 changes: 2 additions & 2 deletions utils.pwsh/Invoke-DevShell.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ function Invoke-DevShell {
@"
`$ErrorActionPreference = 'Stop'
Import-Module '$($VisualStudioData.InstallLocation)/Common7/Tools/Microsoft.VisualStudio.DevShell.dll'
Import-Module '$($VisualStudioData.InstallationPath)/Common7/Tools/Microsoft.VisualStudio.DevShell.dll'
`$_Params = @{
StartInPath = '${BasePath}'
DevCmdArguments = '-arch=${Target} -host_arch=${HostArchitecture}'
VsInstanceId = '$(($VisualStudioData.InstanceId -split ':')[2])'
VsInstanceId = '$($VisualStudioData.InstanceId)'
}
Enter-VsDevShell @_Params
Expand Down
30 changes: 8 additions & 22 deletions utils.pwsh/Setup-Target.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ function Setup-BuildParameters {
$VisualStudioData = Find-VisualStudio

$VisualStudioId = "Visual Studio {0} {1}" -f @(
([System.Version] $VisualStudioData.Version).Major
([regex]::Match($VisualStudioData.Name, "\b\d{4}\b"))
$VisualStudioData.InstallationVersion.Major
( $VisualStudioData.DisplayName -split ' ')[-1]
)

$script:CmakeOptions = @(
Expand Down Expand Up @@ -77,29 +77,15 @@ function Find-VisualStudio {
Find-VisualStudio
#>

$VisualStudioData = Get-CimInstance MSFT_VSInstance

# Prefer VS versions in this order:
# 1. VS2022 Release (stable)
# 2. VS2022 Preview
# 3. VS2019 Release
[string[]]$SupportedVSVersions =
"VisualStudio.17.Release",
"VisualStudio.17.Preview",
"VisualStudio.16.Release"
$NumSupportedVSVersions = $SupportedVSVersions.length

if ( $VisualStudioData.GetType() -eq [object[]] ) {
for ( $i = 0; $i -lt $NumSupportedVSVersions; $i++ ) {
$VisualStudioDataTemp = ($VisualStudioData | Where-Object {$_.ChannelId -eq $SupportedVSVersions[$i]} | Sort-Object -Property Version)[0]
if ( $VisualStudioDataTemp ) {
break;
}
if ( $env:CI -eq $null ) {
if ( ( Get-InstalledModule VSSetup ) -eq $null ) {
Install-Module VSSetup -Scope CurrentUser
}
$VisualStudioData = $VisualStudioDataTemp
}

if ( ! ( $VisualStudioData ) -or ( $VisualStudioData.Version -lt 16 ) ) {
$VisualStudioData = Get-VSSetupInstance -Prerelease:$($script:VSPrerelease) | Select-VSSetupInstance -Version '[16.0,18.0)' -Latest

if ( $VisualStudioData -eq $null ) {
$ErrorMessage = @(
"A Visual Studio installation (2019 or newer) is required for this build script.",
"The Visual Studio Community edition is available for free at https://visualstudio.microsoft.com/vs/community/.",
Expand Down

0 comments on commit 40bc0c0

Please sign in to comment.