forked from dotnet/razor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
startvs.ps1
75 lines (57 loc) · 2.47 KB
/
startvs.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
[CmdletBinding(PositionalBinding=$true)]
Param(
[Parameter(
Position=0,
Mandatory=$false,
HelpMessage="Solution file to open. The default is 'Razor.sln'.")]
[string]$solutionFile=$null,
[Parameter(
Mandatory=$false,
HelpMessage="If specified, choose the Visual Studio version from a list before laucnhing. By default the newest and last installed Visual Studio instance will be launched.")]
[Switch]$chooseVS,
[Parameter(
Mandatory=$false,
HelpMessage="If specified, Roslyn dependencies will be included in the Razor extension when deployed.")]
[Switch]$includeRoslynDeps
)
if ($solutionFile -eq "") {
$solutionFile = "Razor.sln"
}
if ($includeRoslynDeps) {
# Setting this environment variable ensures that the MSBuild will see it when
# building from inside Visual Studio.
$env:IncludeRoslynDeps = $true
}
$dotnetPath = Join-Path (Get-Location) ".dotnet"
# This tells .NET Core to use the same dotnet.exe that build scripts use
$env:DOTNET_ROOT = $dotnetPath
${env:DOTNET_ROOT(x86)} = Join-Path $dotnetPath "x86"
# This tells .NET Core not to go looking for .NET Core in other places
$env:DOTNET_MULTILEVEL_LOOKUP = 0
# Put our local dotnet.exe on PATH first so Visual Studio knows which one to use
$env:PATH = $env:DOTNET_ROOT + ";" + $env:PATH
$vswhere = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe"
if ($chooseVS) {
# Launch vswhere.exe to retrieve a list of installed Visual Studio instances
$vsInstallsJson = &$vswhere -prerelease -format json
$vsInstalls = $vsInstallsJson | ConvertFrom-Json
# Display a menu of Visual Studio instances to the user
Write-Host ""
$index = 1
foreach ($vsInstall in $vsInstalls) {
$channelId = $vsInstall.installedChannelId
$lastDotIndex = $channelId.LastIndexOf(".")
$channelName = $channelId.Substring($lastDotIndex + 1);
Write-Host " $($index) - $($vsInstall.displayName) ($($vsInstall.installationVersion) - $($channelName))"
$index += 1
}
Write-Host ""
$choice = [int](Read-Host "Choose a Visual Studio version to launch")
$vsBasePath = $vsInstalls[$choice - 1].installationPath
}
else {
# Launch vswhere.exe to retrieve the newest, last installed Visual Studio instance
$vsBasePath = &$vswhere -prerelease -latest -property installationPath
}
$vsPath = Join-Path $vsBasePath "Common7\IDE\devenv.exe"
Start-Process $vsPath -ArgumentList $solutionFile