Skip to content

Commit 075612b

Browse files
authored
Install the .NET Core SDK into the repo root instead of UserProfile and 'install' copy of AspNetCore shared framework (#7293)
This is required to workaround several limitations in the way the .NET Core SDK finds shared frameworks and targeting packs. It allow tests to use shared frameworks and targeting packs. It also matches the patterns established in other aspnet and dotnet repos. This should reduce the friction required to adopt Arcade SDK. ## Changes * This moves the default location of the .NET Core SDK installation into `$repoRoot/.dotnet`. This location was already in use for CI builds. * Update the build step for Microsoft.AspNetCore.App to install the shared framework into the local copy of the .NET Core SDK ## Recommendations * Use the "startvs.cmd" script to launch Visual Studio. This will set required environment variables to make VS happier than if you just double click the .sln file. * Use "activate.sh/ps1" if you want to run `dotnet build`, `dotnet test` and other dotnet commands. These will set required environment variables, including PATH. * I recommend removing %USERPROFILE%/.dotnet to your PATH variable if you had added it manually before. This will no longer match what build tools will install. * `git clean -xfd -e .dotnet/` preserves the folder so you don’t have to re-download the SDK again.
1 parent 94a4293 commit 075612b

File tree

13 files changed

+225
-63
lines changed

13 files changed

+225
-63
lines changed

Directory.Build.props

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,14 @@
118118
<IntermediateOutputPath Condition=" '$(PlatformName)' != 'AnyCPU' ">$(BaseIntermediateOutputPath)$(PlatformName)\$(Configuration)\</IntermediateOutputPath>
119119
</PropertyGroup>
120120

121+
<!-- The location of the local installation of the .NET Core shared framework. -->
122+
<PropertyGroup>
123+
<LocalDotNetRoot Condition="'$(TargetOSName)' == 'win'">$(RepositoryRoot).dotnet\$(TargetArchitecture)\</LocalDotNetRoot>
124+
<LocalDotNetRoot Condition="'$(TargetOSName)' != 'win'">$(RepositoryRoot).dotnet\</LocalDotNetRoot>
125+
<!-- Override the SDK default and point to local .dotnet folder. -->
126+
<NetCoreTargetingPackRoot>$(LocalDotNetRoot)packs\</NetCoreTargetingPackRoot>
127+
</PropertyGroup>
128+
121129
<!-- Defines project type conventions. -->
122130
<PropertyGroup>
123131
<RepoRelativeProjectDir>$([MSBuild]::MakeRelative($(RepositoryRoot), $(MSBuildProjectDirectory)))</RepoRelativeProjectDir>

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\x64"
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

build.ps1

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -234,12 +234,7 @@ if (Test-Path $ConfigFile) {
234234
}
235235
}
236236

237-
$DotNetHome = if ($env:DOTNET_HOME) { $env:DOTNET_HOME } `
238-
elseif ($CI) { Join-Path $PSScriptRoot '.dotnet' } `
239-
elseif ($env:USERPROFILE) { Join-Path $env:USERPROFILE '.dotnet'} `
240-
elseif ($env:HOME) {Join-Path $env:HOME '.dotnet'}`
241-
else { Join-Path $PSScriptRoot '.dotnet'}
242-
237+
$DotNetHome = Join-Path $PSScriptRoot '.dotnet'
243238
$env:DOTNET_HOME = $DotNetHome
244239

245240
# Execute
@@ -310,4 +305,5 @@ try {
310305
}
311306
finally {
312307
Remove-Module 'KoreBuild' -ErrorAction Ignore
308+
Remove-Item env:DOTNET_HOME
313309
}

build.sh

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -236,9 +236,6 @@ while [[ $# -gt 0 ]]; do
236236
;;
237237
--ci|-[Cc][Ii])
238238
ci=true
239-
if [[ -z "${DOTNET_HOME:-}" ]]; then
240-
DOTNET_HOME="$DIR/.dotnet"
241-
fi
242239
;;
243240
--verbose|-[Vv]erbose)
244241
verbose=true
@@ -286,8 +283,7 @@ if [ -f "$config_file" ]; then
286283
[ ! -z "${config_tools_source:-}" ] && tools_source="$config_tools_source"
287284
fi
288285

289-
[ -z "${DOTNET_HOME:-}" ] && DOTNET_HOME="$HOME/.dotnet"
290-
export DOTNET_HOME="$DOTNET_HOME"
286+
export DOTNET_HOME="$DIR/.dotnet"
291287

292288
get_korebuild
293289

build/repo.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
$(RepositoryRoot)src\SignalR\clients\ts\**\node_modules\**\*.*proj;
5959
$(RepositoryRoot)src\Components\Blazor\Templates\src\content\**\*.*proj;
6060
$(RepositoryRoot)src\ProjectTemplates\Web.ProjectTemplates\content\**\*.csproj;
61+
$(RepositoryRoot)src\ProjectTemplates\Web.ProjectTemplates\content\**\*.fsproj;
6162
$(RepositoryRoot)src\ProjectTemplates\Web.Spa.ProjectTemplates\content\**\*.csproj;
6263
" />
6364

@@ -159,7 +160,6 @@
159160
$(RepositoryRoot)src\SignalR\**\*.csproj;
160161
$(RepositoryRoot)src\Components\**\*.csproj;
161162
$(RepositoryRoot)src\ProjectTemplates\*\*.csproj;
162-
$(RepositoryRoot)src\ProjectTemplates\test\*.csproj;
163163
$(RepositoryRoot)src\ProjectTemplates\testassets\*\*.csproj;
164164
"
165165
Exclude="

docs/BuildFromSource.md

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ To update an existing copy, run:
5353
git submodule update --init --recursive
5454
```
5555

56-
## Building in Visual Studio / Code
56+
## Building in Visual Studio
5757

5858
Before opening our .sln files in Visual Studio or VS Code, you need to perform the following actions.
5959

@@ -95,30 +95,22 @@ Or you can use this script to automatically traverse the project reference graph
9595

9696
./eng/scripts/AddAllProjectRefsToSolution.ps1 -WorkingDir src/Mvc/
9797

98-
#### PATH
98+
## Building with Visual Studio Code
9999

100-
For VS Code and Visual Studio and `dotnet` commands to work correctly, you must place the following location in your PATH.
101-
Use the following commands to update the PATH variable in a command line window.
100+
Using Visual Studio Code with this repo requires setting environment variables on command line first.
101+
Use these command to launch VS Code with the right settings.
102102

103-
Windows (Command Prompt)
104-
105-
```batch
106-
set PATH=%USERPROFILE%\.dotnet\x64;%PATH%
103+
On Windows (requires PowerShell):
107104
```
108-
109-
Windows (Powershell)
110-
111-
```ps1
112-
$env:PATH="$env:USERPROFILE\.dotnet\x64;$env:PATH"
105+
. activate.ps1
106+
code .
113107
```
114108

115-
Linux/macOS:
116-
117-
```sh
118-
export PATH="$HOME/.dotnet:$PATH"
109+
On macOS/Linux:
110+
```
111+
source activate.sh
112+
code .
119113
```
120-
121-
On Windows, we recommend using the `startvs.cmd` command to launch Visual Studio.
122114

123115
## Building on command-line
124116

@@ -134,6 +126,22 @@ On macOS/Linux:
134126
./build.sh
135127
```
136128

129+
### Using `dotnet` on command line in this repo
130+
131+
Because we are using pre-release versions of .NET Core, you have to set a handful of environment variables
132+
to make the .NET Core command line tool work well. You can set these environment variables like this
133+
134+
On Windows (requires PowerShell):
135+
136+
```ps1
137+
. .\activate.ps1
138+
```
139+
140+
On macOS/Linux:
141+
```bash
142+
source ./activate.sh
143+
```
144+
137145
## Running tests on command-line
138146

139147
Tests are not run by default. Use the `-test` option to run tests in addition to building.

0 commit comments

Comments
 (0)