Skip to content

Commit 56b843e

Browse files
authored
Make VS2019 a prerequisite, and add scripts to set required env vars (#1038)
1 parent e504b4e commit 56b843e

File tree

5 files changed

+166
-7
lines changed

5 files changed

+166
-7
lines changed

Extensions.sln

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio Version 16
44
VisualStudioVersion = 16.0.28508.60
5-
MinimumVisualStudioVersion = 15.0.26124.0
5+
MinimumVisualStudioVersion = 16.0.0.0
66
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "DiagnosticAdapter", "DiagnosticAdapter", "{13B8928D-1FE1-4B9D-8B2C-E3248612052B}"
77
EndProject
88
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Extensions.DiagnosticAdapter", "src\DiagnosticAdapter\src\Microsoft.Extensions.DiagnosticAdapter.csproj", "{EB6915B4-60EC-458F-B5E1-D896AB13363F}"

activate.ps1

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#
2+
# This file must be used by invoking ". activate.ps1" from the command line.
3+
# You cannot run it directly.
4+
# To exit from the environment this creates, execute the 'deactivate' function.
5+
#
6+
7+
function deactivate ([switch]$init) {
8+
9+
# reset old environment variables
10+
if (Test-Path variable:_OLD_PATH) {
11+
$env:PATH = $_OLD_PATH
12+
Remove-Item variable:_OLD_PATH
13+
}
14+
15+
if (test-path function:_old_prompt) {
16+
Set-Item Function:prompt -Value $function:_old_prompt -ea ignore
17+
remove-item function:_old_prompt
18+
}
19+
20+
Remove-Item env:DOTNET_ROOT -ea ignore
21+
Remove-Item env:DOTNET_MULTILEVEL_LOOKUP -ea ignore
22+
if (-not $init) {
23+
# Remove the deactivate function
24+
Remove-Item function:deactivate
25+
}
26+
}
27+
28+
# Cleanup the environment
29+
deactivate -init
30+
31+
$_OLD_PATH = $env:PATH
32+
# Tell dotnet where to find itself
33+
$env:DOTNET_ROOT = "$PSScriptRoot\.dotnet"
34+
# Tell dotnet not to look beyond the DOTNET_ROOT folder for more dotnet things
35+
$env:DOTNET_MULTILEVEL_LOOKUP = 0
36+
# Put dotnet first on PATH
37+
$env:PATH = "${env:DOTNET_ROOT};${env:PATH}"
38+
39+
# Set the shell prompt
40+
if (-not $env:DISABLE_CUSTOM_PROMPT) {
41+
$function:_old_prompt = $function:prompt
42+
function dotnet_prompt {
43+
# Add a prefix to the current prompt, but don't discard it.
44+
write-host "($( split-path $PSScriptRoot -leaf )) " -nonewline
45+
& $function:_old_prompt
46+
}
47+
48+
Set-Item Function:prompt -Value $function:dotnet_prompt -ea ignore
49+
}
50+
51+
Write-Host -f Magenta "Enabled the .NET Core environment. Execute 'deactivate' to exit."
52+
if (-not (Test-Path "${env:DOTNET_ROOT}\dotnet.exe")) {
53+
Write-Host -f Yellow ".NET Core has not been installed yet. Run $PSScriptRoot\restore.cmd to install it."
54+
}
55+
else {
56+
Write-Host "dotnet = ${env:DOTNET_ROOT}\dotnet.exe"
57+
}

activate.sh

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#
2+
# This file must be used by invoking "source activate.sh" from the command line.
3+
# You cannot run it directly.
4+
# To exit from the environment this creates, execute the 'deactivate' function.
5+
6+
_MAGENTA="\033[0;95m"
7+
_YELLOW="\033[0;33m"
8+
_RESET="\033[0m"
9+
10+
deactivate () {
11+
12+
# reset old environment variables
13+
if [ ! -z "${_OLD_PATH:-}" ] ; then
14+
export PATH="$_OLD_PATH"
15+
unset _OLD_PATH
16+
fi
17+
18+
if [ ! -z "${_OLD_PS1:-}" ] ; then
19+
export PS1="$_OLD_PS1"
20+
unset _OLD_PS1
21+
fi
22+
23+
# This should detect bash and zsh, which have a hash command that must
24+
# be called to get it to forget past commands. Without forgetting
25+
# past commands the $PATH changes we made may not be respected
26+
if [ -n "${BASH:-}" ] || [ -n "${ZSH_VERSION:-}" ] ; then
27+
hash -r 2>/dev/null
28+
fi
29+
30+
unset DOTNET_ROOT
31+
unset DOTNET_MULTILEVEL_LOOKUP
32+
if [ ! "${1:-}" = "init" ] ; then
33+
# Remove the deactivate function
34+
unset -f deactivate
35+
fi
36+
}
37+
38+
# Cleanup the environment
39+
deactivate init
40+
41+
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
42+
_OLD_PATH="$PATH"
43+
# Tell dotnet where to find itself
44+
export DOTNET_ROOT="$DIR/.dotnet"
45+
# Tell dotnet not to look beyond the DOTNET_ROOT folder for more dotnet things
46+
export DOTNET_MULTILEVEL_LOOKUP=0
47+
# Put dotnet first on PATH
48+
export PATH="$DOTNET_ROOT:$PATH"
49+
50+
# Set the shell prompt
51+
if [ -z "${DISABLE_CUSTOM_PROMPT:-}" ] ; then
52+
_OLD_PS1="$PS1"
53+
export PS1="(`basename \"$DIR\"`) $PS1"
54+
fi
55+
56+
# This should detect bash and zsh, which have a hash command that must
57+
# be called to get it to forget past commands. Without forgetting
58+
# past commands the $PATH changes we made may not be respected
59+
if [ -n "${BASH:-}" ] || [ -n "${ZSH_VERSION:-}" ] ; then
60+
hash -r 2>/dev/null
61+
fi
62+
63+
echo "${_MAGENTA}Enabled the .NET Core environment. Execute 'deactivate' to exit.${_RESET}"
64+
65+
if [ ! -f "$DOTNET_ROOT/dotnet" ]; then
66+
echo "${_YELLOW}.NET Core has not been installed yet. Run $DIR/restore.sh to install it.${_RESET}"
67+
else
68+
echo "dotnet = $DOTNET_ROOT/dotnet"
69+
fi

docs/build-from-source.md

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,20 @@ Build .NET Extensions from Source
44
Building .NET Extensions from source allows you tweak and customize the API, and
55
to contribute your improvements back to the project.
66

7-
## Install pre-requistes
7+
## Install prerequistes
88

99
### Windows
1010

11-
Building ASP.NET Core on Windows requires:
11+
Building Extensions on Windows requires:
1212

1313
* Windows 7 or higher
1414
* At least 5 GB of disk space and a good internet connection (our build scripts download a lot of tools and dependencies)
15-
* Visual Studio 2017. <https://visualstudio.com>
15+
* Visual Studio 2019. <https://visualstudio.com>
1616
* Git. <https://git-scm.org>
1717

1818
### macOS/Linux
1919

20-
Building ASP.NET Core on macOS or Linux requires:
20+
Building Extensions on macOS or Linux requires:
2121

2222
* If using macOS, you need macOS Sierra or newer.
2323
* If using Linux, you need a machine with all .NET Core Linux prerequisites: <https://docs.microsoft.com/en-us/dotnet/core/linux-prerequisites>
@@ -47,6 +47,38 @@ On macOS/Linux:
4747
./build.sh
4848
```
4949

50+
## Using `dotnet` on command line in this repo
51+
52+
Because we are using pre-release versions of .NET Core, you have to set a handful of environment variables
53+
to make the .NET Core command line tool work well. You can set these environment variables like this
54+
55+
On Windows (requires PowerShell):
56+
```
57+
. activate.ps1
58+
```
59+
60+
On macOS/Linux:
61+
```
62+
source activate.sh
63+
```
64+
65+
## Building with Visual Studio Code
66+
67+
Using Visual Studio Code with this repo requires setting environment variables on command line first.
68+
Use these command to launch VS Code with the right settings.
69+
70+
On Windows (requires PowerShell):
71+
```
72+
. activate.ps1
73+
code .
74+
```
75+
76+
On macOS/Linux:
77+
```
78+
source activate.sh
79+
code .
80+
```
81+
5082
## Use the result of your build
5183

5284
After building Extensions from source, you can use these in a project by pointing NuGet to the folder containing the .nupkg files.
@@ -58,7 +90,7 @@ After building Extensions from source, you can use these in a project by pointin
5890
<configuration>
5991
<packageSources>
6092
<clear />
61-
<add key="MyBuildOfExtensions" value="C:\src\aspnet\Extensions\artifacts\packages\Debug\Shipping\" />
93+
<add key="MyBuildOfExtensions" value="C:\src\Extensions\artifacts\packages\Debug\Shipping\" />
6294
<add key="NuGet.org" value="https://api.nuget.org/v3/index.json" />
6395
</packageSources>
6496
</configuration>

startvs.cmd

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ SET PATH=%DOTNET_ROOT%;%PATH%
1414
SET sln=%1
1515

1616
IF NOT EXIST "%DOTNET_ROOT%\dotnet.exe" (
17-
restore.cmd
17+
echo .NET Core has not yet been installed. Running restore.cmd to install it.
18+
call restore.cmd
1819
)
1920

2021
start %~dp0Extensions.sln

0 commit comments

Comments
 (0)