未验证 提交 594c6592 编写于 作者: T Tomáš Matoušek 提交者: GitHub

Misc improvements in Roslyn preview installer scripts. (#32654)

Allow installing on Dev16.
Allow to specify rootSuffix.
Bump min required VS version to 15.8.
Misc cleanup.
上级 91a119b2
@echo off
powershell -noprofile -executionPolicy Unrestricted -file "%~dp0\tools\install.ps1"
powershell -noprofile -executionPolicy Unrestricted -command "& """%~dp0tools\install.ps1""" %*"
@echo off
powershell -noprofile -executionPolicy Unrestricted -file "%~dp0\tools\uninstall.ps1"
powershell -noprofile -executionPolicy Unrestricted -command "& """%~dp0tools\uninstall.ps1""" %*"
[CmdletBinding(PositionalBinding=$false)]
param (
[string][Alias("hive")]$rootSuffix = ""
)
Set-StrictMode -version 2.0
$ErrorActionPreference="Stop"
......@@ -10,49 +15,54 @@ try {
}
# Welcome Message
Write-Host "Installing Roslyn Insiders Build" -ForegroundColor Green
Write-Host "Installing Roslyn Preview Build" -ForegroundColor Green
# Find VS Instance
$vsInstalls = Get-VisualStudioDirAndId
$vsDir = $vsInstalls[0].Trim("\")
$vsId = $vsInstalls[1]
$vsInstances = Get-VisualStudioInstances
# We are given two strings per VS instance (vsdir and vsid)
# Check to see if more than one instance meets our reqs
if ($vsInstalls.Count -gt 2) {
if ($vsInstances.Count -gt 1) {
while ($true) {
Write-Host "Multiple Visual Studio Installs Detected" -ForegroundColor White
Write-Host "Please Select an Instance to Install Into:" -ForegroundColor White
$number=1
For($i=0; $i -lt $vsInstalls.Count; $i+=2){
$tempVsDir = $vsInstalls[$i].Trim("\")
$tempVsExe = Join-Path $tempVsDir "Common7\IDE\devenv.exe"
Write-Host "[$number]: $tempVsExe" -ForegroundColor White
$number++
Write-Host "Multiple Visual Studio instances detected" -ForegroundColor White
Write-Host "Please select an instance to install into:" -ForegroundColor White
for ($i=0; $i -lt $vsInstances.Length; $i++) {
$devenvPath = Join-Path $vsInstances[$i].installationPath "Common7\IDE\devenv.exe"
Write-Host "[$($i + 1)]: $devenvPath" -ForegroundColor White
}
$input = Read-Host
$vsInstallNumber = $input -as [int]
if ($vsInstallNumber -is [int] -and $vsInstallNumber -le ($number-1)) {
$index = ($vsInstallNumber -1) * 2
$vsDir = $vsInstalls[$index].Trim("\")
$vsId = $vsInstalls[$index+1]
if (($vsInstallNumber -is [int]) -and ($vsInstallNumber -gt 0) -and ($vsInstallNumber -le $vsInstances.Length)) {
$vsInstance = $vsInstances[$vsInstallNumber - 1]
break
}
Write-Host ""
}
} else {
$vsInstance = $vsInstances[0]
}
$vsDir = $vsInstance.installationPath.Trim("\")
$vsId = $vsInstance.instanceId
$vsMajorVersion = $vsInstance.installationVersion.Split(".")[0]
# Install VSIX
$vsExe = Join-Path $vsDir "Common7\IDE\devenv.exe"
Write-Host "Installing Preview Into $vsExe" -ForegroundColor Gray
Uninstall-VsixViaTool -vsDir $vsDir -vsId $vsId -hive ""
Install-VsixViaTool -vsDir $vsDir -vsId $vsId -hive ""
Write-Host "Installing Preview into $vsExe" -ForegroundColor Gray
Uninstall-VsixViaTool -vsDir $vsDir -vsId $vsId -rootSuffix $rootSuffix
Install-VsixViaTool -vsDir $vsDir -vsId $vsId -rootSuffix $rootSuffix
# Clear MEF Cache
Write-Host "Refreshing MEF Cache" -ForegroundColor Gray
$mefCacheFolder = Join-Path $env:LOCALAPPDATA "Microsoft\VisualStudio\15.0_$vsId\ComponentModelCache"
Get-ChildItem -Path $mefCacheFolder -Include *.* -File -Recurse | foreach { Remove-Item $_}
$mefCacheFolder = Get-MefCacheDir -vsMajorVersion $vsMajorVersion -vsId $vsId -rootSuffix $rootSuffix
if (Test-Path $mefCacheFolder) {
Get-ChildItem -Path $mefCacheFolder -Include *.* -File -Recurse | foreach { Remove-Item $_ }
}
$args = "/updateconfiguration"
Exec-Console $vsExe $args
......
[CmdletBinding(PositionalBinding=$false)]
param (
[string][Alias("hive")]$rootSuffix = ""
)
Set-StrictMode -version 2.0
$ErrorActionPreference="Stop"
try {
. (Join-Path $PSScriptRoot "utils.ps1")
if (Test-Process "devenv") {
Write-Host "Please shut down all instances of Visual Studio before running" -ForegroundColor Red
exit 1
Write-Host "Please shut down all instances of Visual Studio before running" -ForegroundColor Red
exit 1
}
# Find VS Instance
$vsInstalls = Get-VisualStudioDirAndId
$vsDir = $vsInstalls[0].Trim("\")
$vsId = $vsInstalls[1]
# Uninstall VSIX
Write-Host "Uninstalling Preview Everywhere..." -ForegroundColor Green
for ($i = 0; $i -lt $vsInstalls.Count; $i+=2) {
$vsDir = $vsInstalls[$i].Trim("\")
$vsId = $vsInstalls[$i+1]
Uninstall-VsixViaTool -vsDir $vsDir -vsId $vsId -hive ""
# Clear MEF Cache
Write-Host "Refreshing MEF Cache" -ForegroundColor Gray
$mefCacheFolder = Join-Path $env:LOCALAPPDATA "Microsoft\VisualStudio\15.0_$vsId\ComponentModelCache"
Get-ChildItem -Path $mefCacheFolder -Include *.* -File -Recurse | foreach { Remove-Item $_}
$vsExe = Join-Path $vsDir "Common7\IDE\devenv.exe"
$args = "/updateconfiguration"
Exec-Console $vsExe $args
$vsInstances = Get-VisualStudioInstances
# Uninstall VSIX from all instances
Write-Host "Uninstalling Roslyn Preview ..." -ForegroundColor Green
foreach ($vsInstance in $vsInstances) {
$vsDir = $vsInstance.installationPath.Trim("\")
$vsId = $vsInstance.instanceId
$vsMajorVersion = $vsInstance.installationVersion.Split(".")[0]
Uninstall-VsixViaTool -vsDir $vsDir -vsId $vsId -rootSuffix $rootSuffix
# Clear MEF Cache
Write-Host "Refreshing MEF Cache" -ForegroundColor Gray
$mefCacheFolder = Get-MefCacheDir -vsMajorVersion $vsMajorVersion -vsId $vsId -rootSuffix $rootSuffix
if (Test-Path $mefCacheFolder) {
Get-ChildItem -Path $mefCacheFolder -Include *.* -File -Recurse | foreach { Remove-Item $_ }
}
$vsExe = Join-Path $vsDir "Common7\IDE\devenv.exe"
$args = "/updateconfiguration"
Exec-Console $vsExe $args
}
Write-Host "Uninstall Succeeded" -ForegroundColor Green
exit 0
}
......
......@@ -72,33 +72,20 @@ function Exec-Console([string]$command, [string]$commandArgs) {
}
# Get the directory and instance ID of the first Visual Studio version which
# Returns an array of JSON objects, each item representing an installed instance of Visual Studio that
# meets our minimal requirements for the Roslyn repo.
function Get-VisualStudioDirAndId() {
# Throws if there is none.
function Get-VisualStudioInstances() {
$minVersionStr = "15.8"
$vswhere = Join-Path $PSScriptRoot "vswhere\vswhere.exe"
$output = Exec-Command $vswhere "-prerelease -requires Microsoft.VisualStudio.Component.Roslyn.Compiler -version [15.5,15.9) -format json" | Out-String
$j = ConvertFrom-Json $output
$foundVsInstall = $false
foreach ($obj in $j) {
# Need to be using at least Visual Studio 15.5 in order to have the appropriate
# set of SDK fixes. Parsing the installationName is the only place where this is
# recorded in that form.
$name = $obj.installationName
if ($name -match "VisualStudio(Preview)?/([\d.]+)(\+|-).*") {
$minVersion = New-Object System.Version "15.5.0"
$maxVersion = New-Object System.Version "15.9.0"
$version = New-Object System.Version $matches[2]
if ($version -ge $minVersion -and $version -lt $maxVersion) {
Write-Output $obj.installationPath
Write-Output $obj.instanceId
$foundVsInstall = $true;
}
}
}
$vsInstances = Exec-Command $vswhere "-prerelease -requires Microsoft.VisualStudio.Component.Roslyn.Compiler -version $minVersionStr -format json" | ConvertFrom-Json
if (-not $foundVsInstall) {
throw "Could not find a suitable Visual Studio Version"
if ($vsInstances.Length -eq 0) {
throw "Could not find a suitable Visual Studio version. Minimal required version is $minVersionStr."
}
return $vsInstances
}
function Test-Process([string]$processName) {
......@@ -106,21 +93,20 @@ function Test-Process([string]$processName) {
return $all -ne $null
}
function Install-VsixViaTool([string]$vsDir, [string]$vsId, [string]$hive) {
$baseArgs = "/rootSuffix:$hive /vsInstallDir:`"$vsDir`""
$vsixes = @("vsix\RoslynDeployment.vsix")
Use-VsixTool -vsDir $vsDir -vsId $vsId -baseArgs $baseArgs -hive $hive -vsixes $vsixes
function Get-MefCacheDir([string]$vsMajorVersion, [string]$vsId, [string]$rootSuffix) {
return Join-Path $env:LOCALAPPDATA "Microsoft\VisualStudio\$vsMajorVersion.0_$vsId$rootSuffix\ComponentModelCache"
}
function Uninstall-VsixViaTool([string]$vsDir, [string]$vsId, [string]$hive) {
$baseArgs = "/rootSuffix:$hive /u /vsInstallDir:`"$vsDir`""
function Install-VsixViaTool([string]$vsDir, [string]$vsId, [string]$rootSuffix) {
Use-VsixTool -vsDir $vsDir -vsId $vsId -rootSuffix $rootSuffix
}
function Uninstall-VsixViaTool([string]$vsDir, [string]$vsId, [string]$rootSuffix) {
$attempt = 3
$success = $false
while ($attempt -gt 0 -and -not $success) {
try {
$vsixes = @("vsix\RoslynDeployment.vsix")
Use-VsixTool -vsDir $vsDir -vsId $vsId -baseArgs $baseArgs -hive $hive -vsixes $vsixes
Use-VsixTool -vsDir $vsDir -vsId $vsId -rootSuffix $rootSuffix -additionalArgs "/u"
$success = $true
} catch {
# remember error information
......@@ -137,15 +123,15 @@ function Uninstall-VsixViaTool([string]$vsDir, [string]$vsId, [string]$hive) {
}
}
function Use-VsixTool([string]$vsDir, [string]$vsId, [string]$baseArgs, [string]$hive, [string[]]$vsixes) {
$vsixExe = Join-Path $PSScriptRoot "vsixexpinstaller\VsixExpInstaller.exe"
$vsixExe = "`"$vsixExe`""
function Use-VsixTool([string]$vsDir, [string]$vsId, [string]$rootSuffix, [string]$additionalArgs = "") {
$installerExe = Join-Path $PSScriptRoot "vsixexpinstaller\VsixExpInstaller.exe"
Write-Host "Using VS Instance $vsId at `"$vsDir`"" -ForegroundColor Gray
foreach ($e in $vsixes) {
$name = $e
$filePath = "`"$((Resolve-Path $e).Path)`""
$fullArg = "$baseArgs $filePath"
Exec-Console $vsixExe $fullArg
$vsixFileNames = @("RoslynDeployment.vsix")
$rootSuffixArg = if ($rootSuffix) { "/rootSuffix:`"$rootSuffix`"" } else { "" }
foreach ($vsixFileName in $vsixFileNames) {
$vsixPath = Resolve-Path (Join-Path $PSScriptRoot "..\vsix\$vsixFileName")
Exec-Console "`"$installerExe`"" "`"$vsixPath`" /vsInstallDir:`"$vsDir`" $rootSuffixArg $additionalArgs"
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册