diff --git a/Build-Dependencies.ps1 b/Build-Dependencies.ps1 index 54106e006..3cf42a546 100644 --- a/Build-Dependencies.ps1 +++ b/Build-Dependencies.ps1 @@ -12,6 +12,7 @@ param( [switch] $SkipBuild, [switch] $SkipDeps, [switch] $SkipUnpack + [switch] $VSPrerelease ) $ErrorActionPreference = "Stop" diff --git a/utils.pwsh/Invoke-DevShell.ps1 b/utils.pwsh/Invoke-DevShell.ps1 index eca2796e2..3e1fb2398 100644 --- a/utils.pwsh/Invoke-DevShell.ps1 +++ b/utils.pwsh/Invoke-DevShell.ps1 @@ -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 diff --git a/utils.pwsh/Setup-Target.ps1 b/utils.pwsh/Setup-Target.ps1 index affe82c78..bee3ac506 100644 --- a/utils.pwsh/Setup-Target.ps1 +++ b/utils.pwsh/Setup-Target.ps1 @@ -39,8 +39,8 @@ function Setup-BuildParameters { $VisualStudioData = Find-VisualStudio $VisualStudioId = "Visual Studio {0} {1}" -f @( - ([System.Version] $VisualStudioData.Version).Major - ( $VisualStudioData.Name -split ' ')[3] + $VisualStudioData.InstallationVersion.Major + ( $VisualStudioData.DisplayName -split ' ')[3] ) $script:CmakeOptions = @( @@ -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; - } - } - $VisualStudioData = $VisualStudioDataTemp + $VSSetupData = Get-InstalledModule VSSetup -ErrorAction SilentlyContinue + + if ( $VSSetupData -eq $null ) { + Install-Module VSSetup -Scope CurrentUser } - 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/.",