Skip to content

Commit de07f2d

Browse files
authored
Scripts to launch VS and VS Code using local SDK (#2640)
1 parent cbbea28 commit de07f2d

File tree

4 files changed

+92
-2
lines changed

4 files changed

+92
-2
lines changed

generate-dev-sln.ps1

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,4 @@ $slnFile = Get-Content $devSln
3737
#dotnet sln uses an older ProjectType Guid
3838
$slnFile -replace 'FAE04EC0-301F-11D3-BF4B-00C04F79EFBC', '9A19103F-16F7-4668-BE54-9A1E7A4F7556' | Out-File $devSln
3939

40-
$devenvPath = & "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe" -latest -prerelease -property productPath
41-
& $devenvPath $PSScriptRoot\dotnet-monitor.dev.sln
40+
& "$PSScriptRoot\startvs.cmd" $PSScriptRoot\dotnet-monitor.dev.sln

startvs.cmd

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
@ECHO OFF
2+
SETLOCAL
3+
SETLOCAL EnableDelayedExpansion
4+
5+
:: This command launches a Visual Studio solution with environment variables required to use a local version of the .NET Core SDK.
6+
7+
:: This tells .NET Core to use the same dotnet.exe that build scripts use
8+
SET DOTNET_ROOT=%~dp0.dotnet
9+
SET DOTNET_ROOT(x86)=%~dp0.dotnet\x86
10+
11+
:: This tells .NET Core not to go looking for .NET Core in other places
12+
SET DOTNET_MULTILEVEL_LOOKUP=0
13+
14+
:: Put our local dotnet.exe on PATH first so Visual Studio knows which one to use
15+
SET PATH=%DOTNET_ROOT%;%PATH%
16+
17+
SET sln=%~1
18+
19+
IF NOT EXIST "%DOTNET_ROOT%\dotnet.exe" (
20+
echo .NET Core has not yet been installed. Run `%~dp0restore.cmd` to install tools
21+
exit /b 1
22+
)
23+
24+
IF "%sln%"=="" (
25+
SET sln=%~dp0dotnet-monitor.sln
26+
echo Automatically chose solution file !sln!
27+
)
28+
29+
IF "%VSINSTALLDIR%" == "" (
30+
start "" "%sln%"
31+
) else (
32+
"%VSINSTALLDIR%\Common7\IDE\devenv.com" "%sln%"
33+
)

startvscode.cmd

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
@ECHO OFF
2+
SETLOCAL
3+
4+
:: This command launches a Visual Studio code 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+
:: Sets TFW for Visual Studio Code usage
17+
SET TARGET=net7.0
18+
19+
SET folder=%~1
20+
21+
IF NOT EXIST "%DOTNET_ROOT%\dotnet.exe" (
22+
echo .NET Core has not yet been installed. Run `%~dp0restore.cmd` to install tools
23+
exit /b 1
24+
)
25+
26+
IF "%folder%"=="" (
27+
code .
28+
) else (
29+
code "%folder%"
30+
)

startvscode.sh

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
4+
# This command launches a Visual Studio code 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+
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
8+
export DOTNET_ROOT="$DIR/.dotnet"
9+
10+
# This tells .NET Core not to go looking for .NET Core in other places
11+
export DOTNET_MULTILEVEL_LOOKUP=0
12+
13+
# Put our local dotnet on PATH first so Visual Studio knows which one to use
14+
export PATH="$DOTNET_ROOT:$PATH"
15+
16+
# Sets TFW for Visual Studio Code usage
17+
export TARGET=net7.0
18+
19+
if [ ! -f "$DOTNET_ROOT/dotnet" ]; then
20+
echo ".NET Core has not yet been installed. Run `./restore.sh` to install tools."
21+
exit 1
22+
fi
23+
24+
if [ -z "$1" ]; then
25+
code .
26+
else
27+
code $1
28+
fi

0 commit comments

Comments
 (0)