diff options
Diffstat (limited to 'scripts')
| -rw-r--r-- | scripts/findAnyMSBuildWithCppPlatformToolset.ps1 | 172 | ||||
| -rw-r--r-- | scripts/findVisualStudioInstallationInstances.ps1 | 49 |
2 files changed, 55 insertions, 166 deletions
diff --git a/scripts/findAnyMSBuildWithCppPlatformToolset.ps1 b/scripts/findAnyMSBuildWithCppPlatformToolset.ps1 index f72491e5d..632cc2cdf 100644 --- a/scripts/findAnyMSBuildWithCppPlatformToolset.ps1 +++ b/scripts/findAnyMSBuildWithCppPlatformToolset.ps1 @@ -1,164 +1,50 @@ [CmdletBinding()] param( [Parameter(Mandatory=$False)] - [switch]$DisableVS2017 = $False, - - [Parameter(Mandatory=$False)] - [switch]$DisableVS2015 = $False + [string]$explicitlyRequestedVSPath = "" ) -if ($DisableVS2017 -and $DisableVS2015) -{ - throw "Both VS2015 and VS2017 were disabled." -} - -function New-MSBuildInstance() -{ - param ($msbuildExePath, $toolsetVersion) - - $instance = new-object PSObject - $instance | add-member -type NoteProperty -Name msbuildExePath -Value $msbuildExePath - $instance | add-member -type NoteProperty -Name toolsetVersion -Value $toolsetVersion +$explicitlyRequestedVSPath = $explicitlyRequestedVSPath -replace "\\$" # Remove potential trailing backslash - return $instance -} - -Write-Verbose "Executing $($MyInvocation.MyCommand.Name) with DisableVS2017=$DisableVS2017, DisableVS2015=$DisableVS2015" $scriptsDir = split-path -parent $MyInvocation.MyCommand.Definition - -$validInstances = New-Object System.Collections.ArrayList - -# VS2017 -Write-Verbose "`n`n" -Write-Verbose "Checking for MSBuild from VS2017 instances..." -$VisualStudio2017InstallationInstances = & $scriptsDir\findVisualStudioInstallationInstances.ps1 -Write-Verbose "VS2017 Candidates: $([system.String]::Join(',', $VisualStudio2017InstallationInstances))" -foreach ($instanceCandidate in $VisualStudio2017InstallationInstances) -{ - $VCFolder= "$instanceCandidate\VC\Tools\MSVC\" - - if (Test-Path $VCFolder) - { - $instance = New-MSBuildInstance "$instanceCandidate\MSBuild\15.0\Bin\MSBuild.exe" "v141" - Write-Verbose "Found $instance" - $validInstances.Add($instance) > $null - } -} - -# VS2015 - in Program Files -Write-Verbose "`n`n" -Write-Verbose "Checking for MSBuild from VS2015 in Program Files..." -$CandidateProgramFiles = $(& $scriptsDir\getProgramFiles32bit.ps1), $(& $scriptsDir\getProgramFilesPlatformBitness.ps1) -Write-Verbose "Program Files Candidate locations: $([system.String]::Join(',', $CandidateProgramFiles))" -foreach ($ProgramFiles in $CandidateProgramFiles) -{ - $clExe= "$ProgramFiles\Microsoft Visual Studio 14.0\VC\bin\cl.exe" - - if (!(Test-Path $clExe)) - { - Write-Verbose "$clExe - Not Found" - continue - } - - Write-Verbose "$clExe - Found" - $instance = New-MSBuildInstance "$ProgramFiles\MSBuild\14.0\Bin\MSBuild.exe" "v140" - Write-Verbose "Found $instance" - $validInstances.Add($instance) > $null -} - -# VS2015 - through the registry -function NewCppRegistryPair() -{ - param ($visualStudioEntry, $msBuildEntry) - - $instance = new-object PSObject - $instance | add-member -type NoteProperty -Name visualStudioEntry -Value $visualStudioEntry - $instance | add-member -type NoteProperty -Name msBuildEntry -Value $msBuildEntry - - return $instance -} - -Write-Verbose "`n`n" -Write-Verbose "Checking for MSBuild from VS2015 through the registry..." - -$registryPairs = -$(NewCppRegistryPair "Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\visualstudio\14.0" "Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\msbuild\toolsversions\14.0"), -$(NewCppRegistryPair "Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\visualstudio\14.0" "Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\msbuild\toolsversions\14.0") - -foreach ($pair in $registryPairs) +$VisualStudioInstallationInstances = & $scriptsDir\findVisualStudioInstallationInstances.ps1 +Write-Verbose "VS Candidates:`n`r$([system.String]::Join([Environment]::NewLine, $VisualStudioInstallationInstances))" +foreach ($instanceCandidate in $VisualStudioInstallationInstances) { - $vsEntry = $pair.visualStudioEntry - try - { - $VS14InstallDir = $(gp $vsEntry InstallDir -erroraction Stop | % { $_.InstallDir }) - Write-Verbose "$vsEntry\InstallDir - Found" - } - catch - { - Write-Verbose "$vsEntry\InstallDir - Not Found" - continue - } - - Write-Verbose "$VS14InstallDir - Obtained from registry" - # We want "${VS14InstallDir}..\..\VC\bin\cl.exe" - # Doing Split-path to avoid the ..\.. from appearing in the output - $clExePath = Split-path $VS14InstallDir -Parent - $clExePath = Split-path $clExePath -Parent - $clExePath = "$clExePath\VC\bin\cl.exe" - - if (!(Test-Path $clExePath)) - { - Write-Verbose "$clExePath - Not Found" - continue - } + Write-Verbose "Inspecting: $instanceCandidate" + $split = $instanceCandidate -split "::" + # $preferenceWeight = $split[0] + # $releaseType = $split[1] + $version = $split[2] + $path = $split[3] - Write-Verbose "$clExePath - Found" - - $msbuildEntry = $pair.msBuildEntry - try - { - $MSBuild14 = $(gp $msbuildEntry MSBuildToolsPath -erroraction Stop | % { $_.MSBuildToolsPath }) - Write-Verbose "$msbuildEntry\MSBuildToolsPath - Found" - } - catch - { - Write-Verbose "$msbuildEntry\MSBuildToolsPath - Not Found" - continue - } - - Write-Verbose "${MSBuild14} - Obtained from registry" - $msbuildPath = "${MSBuild14}MSBuild.exe" - if (!(Test-Path $msbuildPath)) + if ($explicitlyRequestedVSPath -ne "" -and $explicitlyRequestedVSPath -ne $path) { - Write-Verbose "$msbuildPath - Not Found" + Write-Verbose "Skipping: $instanceCandidate" continue } - $instance = New-MSBuildInstance $msbuildPath "v140" - Write-Verbose "Found $instance" - $validInstances.Add($instance) > $null -} - -Write-Verbose "`n`n`n" -Write-Verbose "The following MSBuild instances were found:" -foreach ($instance in $validInstances) -{ - Write-Verbose $instance -} - -# Selecting -foreach ($instance in $validInstances) -{ - if (!$DisableVS2017 -and $instance.toolsetVersion -eq "v141") + $majorVersion = $version.Substring(0,2); + if ($majorVersion -eq "15") { - return $instance.msbuildExePath, $instance.toolsetVersion + $VCFolder= "$path\VC\Tools\MSVC\" + if (Test-Path $VCFolder) + { + Write-Verbose "Picking: $instanceCandidate" + return "$path\MSBuild\15.0\Bin\MSBuild.exe", "v141" + } } - if (!$DisableVS2015 -and $instance.toolsetVersion -eq "v140") + if ($majorVersion -eq "14") { - return $instance.msbuildExePath, $instance.toolsetVersion + $clExe= "$path\VC\bin\cl.exe" + if (Test-Path $clExe) + { + Write-Verbose "Picking: $instanceCandidate" + $programFilesPath = split-path -parent $path + return "$programFilesPath\MSBuild\14.0\Bin\MSBuild.exe", "v140" + } } } - throw "Could not find MSBuild version with C++ support. VS2015 or VS2017 (with C++) needs to be installed."
\ No newline at end of file diff --git a/scripts/findVisualStudioInstallationInstances.ps1 b/scripts/findVisualStudioInstallationInstances.ps1 index ca807980c..8c67ef6d6 100644 --- a/scripts/findVisualStudioInstallationInstances.ps1 +++ b/scripts/findVisualStudioInstallationInstances.ps1 @@ -4,32 +4,35 @@ param( ) $scriptsDir = split-path -parent $MyInvocation.MyCommand.Definition -$vcpkgRootDir = & $scriptsDir\findFileRecursivelyUp.ps1 $scriptsDir .vcpkg-root +$vswhereExe = & $scriptsDir\fetchDependency.ps1 "vswhere" -$downloadsDir = "$vcpkgRootDir\downloads" +$output = & $vswhereExe -prerelease -legacy -format xml +[xml]$asXml = $output -$nugetexe = & $scriptsDir\fetchDependency.ps1 "nuget" -$nugetPackageDir = "$downloadsDir\nuget-packages" - -$SetupAPIVersion = "1.8.24" -Write-Verbose "Fetching Microsoft.VisualStudio.Setup.Configuration.Native@$SetupAPIVersion from NuGet." -$nugetOutput = & $nugetexe install Microsoft.VisualStudio.Setup.Configuration.Native -Version $SetupAPIVersion -OutputDirectory $nugetPackageDir -Source "https://api.nuget.org/v3/index.json" -nocache 2>&1 -Write-Verbose "Fetching Microsoft.VisualStudio.Setup.Configuration.Native@$SetupAPIVersion from NuGet. Done." - -$SetupConsoleExe = "$nugetPackageDir\Microsoft.VisualStudio.Setup.Configuration.Native.$SetupAPIVersion\tools\x86\Microsoft.VisualStudio.Setup.Configuration.Console.exe" - -if (!(Test-Path $SetupConsoleExe)) +$results = New-Object System.Collections.ArrayList +foreach ($instance in $asXml.instances.instance) { - throw $nugetOutput + $installationPath = $instance.InstallationPath -replace "\\$" # Remove potential trailing backslash + $installationVersion = $instance.InstallationVersion + $isPrerelease = $instance.IsPrerelease + if ($isPrerelease -eq 0) + { + $releaseType = "PreferenceWeight3::StableRelease" + } + elseif ($isPrerelease -eq 1) + { + $releaseType = "PreferenceWeight2::PreRelease" + } + else + { + $releaseType = "PreferenceWeight1::Legacy" + } + + # Placed like that for easy sorting according to preference + $results.Add("${releaseType}::${installationVersion}::${installationPath}") > $null } -$instances = & $SetupConsoleExe -nologo -value InstallationPath 2>&1 -$instanceCount = $instances.Length - -# The last item can be empty -if ($instanceCount -gt 0 -and $instances[$instanceCount - 1] -eq "") -{ - $instances = $instances[0..($instanceCount - 2)] -} +$results.Sort() +$results.Reverse() -return $instances +return $results
\ No newline at end of file |
