Skip to content

Commit c60efd0

Browse files
Update StartVS script
This change updates the StartVS script in the following ways: * Ported batch file to a PowerShell script. The batch file is still there. It just runs the PowerShell script. * Added a `-chooseVS` switch that displays a menu of Visual Studio instances that are installed and allows the user to pick one to launch. * Added an `-includeRoslynDeps` switch that sets an environment variable that controls whether Roslyn dependencies are included with the Razor extension or not.
1 parent 798007f commit c60efd0

File tree

2 files changed

+78
-26
lines changed

2 files changed

+78
-26
lines changed

startvs.cmd

+3-26
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,4 @@
1-
@ECHO OFF
2-
SETLOCAL
1+
@echo off
2+
setlocal
33

4-
:: This command launches a Visual Studio solution with environment variables required to use a local version of the .NET Core SDK.
5-
6-
:: This tells .NET Core to use the same dotnet.exe that build scripts use
7-
SET DOTNET_ROOT=%~dp0.dotnet
8-
SET DOTNET_ROOT(x86)=%~dp0.dotnet\x86
9-
10-
:: This tells .NET Core not to go looking for .NET Core in other places
11-
SET DOTNET_MULTILEVEL_LOOKUP=0
12-
13-
:: Put our local dotnet.exe on PATH first so Visual Studio knows which one to use
14-
SET PATH=%DOTNET_ROOT%;%PATH%
15-
16-
SET sln=%~1
17-
18-
IF "%sln%"=="" (
19-
SET sln=%~dp0\Razor.sln
20-
)
21-
22-
IF NOT EXIST "%DOTNET_ROOT%\dotnet.exe" (
23-
echo .NET Core has not yet been installed. Run `%~dp0restore.cmd` to install tools
24-
exit /b 1
25-
)
26-
27-
start "" "%sln%"
4+
powershell -ExecutionPolicy ByPass -NoProfile -Command "& '%~dp0startvs.ps1'" %*

startvs.ps1

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

0 commit comments

Comments
 (0)