Skip to content

Commit 3a067cc

Browse files
[build] clean up past .NET 5 installations (#5103)
Context: https://docs.microsoft.com/dotnet/core/tools/dotnet-install-script The `use-dot-net.yaml` template is leaving behind old installations of .NET 5: $ dotnet --list-sdks 3.1.201 [/Users/builder/.dotnet/sdk] 5.0.100-preview.6.20265.2 [/Users/builder/.dotnet/sdk] 5.0.100-preview.7.20307.3 [/Users/builder/.dotnet/sdk] 5.0.100-rc.1.20365.11 [/Users/builder/.dotnet/sdk] 5.0.100-rc.1.20411.10 [/Users/builder/.dotnet/sdk] 5.0.100-rc.1.20414.5 [/Users/builder/.dotnet/sdk] 5.0.100-rc.1.20426.3 [/Users/builder/.dotnet/sdk] 5.0.100-rc.2.20458.11 [/Users/builder/.dotnet/sdk] We are currently using `dotnet-install.sh` or `dotnet-install.ps1` to install nightly builds of .NET 5. These scripts basically download a `.zip` file and extract them. I added a new `remove_dotnet` parameter to delete the `dotnet` directory completely. This will ensure we only have the versions of .NET Core 3.x and .NET 5 specified in our build definition. Usage would look like: - template: yaml-templates/use-dot-net.yaml parameters: version: $(DotNetCorePreviewVersion) remove_dotnet: true - template: yaml-templates/use-dot-net.yaml parameters: version: $(DotNetCoreVersion) Simply deleting the directories is similar to what the [`dotnet-uninstall-pkgs.sh`][0] script does. [0]: https://github.com/dotnet/sdk/blob/feae865a0614026d72ed9a9558d0111e5fcd5765/scripts/obtain/uninstall/dotnet-uninstall-pkgs.sh#L35
1 parent 696530d commit 3a067cc

File tree

4 files changed

+12
-2
lines changed

4 files changed

+12
-2
lines changed

build-tools/automation/azure-pipelines-oss.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ stages:
5252
- template: yaml-templates/use-dot-net.yaml
5353
parameters:
5454
version: $(DotNetCorePreviewVersion)
55+
remove_dotnet: true
5556

5657
- template: yaml-templates/use-dot-net.yaml
5758
parameters:

build-tools/automation/azure-pipelines.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ stages:
138138
- template: yaml-templates/use-dot-net.yaml
139139
parameters:
140140
version: $(DotNetCorePreviewVersion)
141+
remove_dotnet: true
141142

142143
- template: yaml-templates/use-dot-net.yaml
143144
parameters:
@@ -283,6 +284,7 @@ stages:
283284
- template: yaml-templates\use-dot-net.yaml
284285
parameters:
285286
version: $(DotNetCorePreviewVersion)
287+
remove_dotnet: true
286288

287289
- template: yaml-templates\use-dot-net.yaml
288290
parameters:

build-tools/automation/yaml-templates/setup-test-environment.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ steps:
2424
- template: use-dot-net.yaml
2525
parameters:
2626
version: $(DotNetCorePreviewVersion)
27+
remove_dotnet: true
2728

2829
- template: use-dot-net.yaml
2930
parameters:

build-tools/automation/yaml-templates/use-dot-net.yaml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,29 @@
33

44
parameters:
55
version: $(DotNetCoreVersion)
6+
remove_dotnet: false
67

78
steps:
89

910
- powershell: |
1011
$ErrorActionPreference = 'Stop'
1112
$ProgressPreference = 'SilentlyContinue'
13+
$DotNetRoot = "$env:ProgramFiles\dotnet\"
14+
if ("${{ parameters.remove_dotnet }}" -eq $true) {
15+
Remove-Item -Recurse $DotNetRoot -Verbose
16+
}
1217
Invoke-WebRequest -Uri "https://dot.net/v1/dotnet-install.ps1" -OutFile dotnet-install.ps1
13-
& .\dotnet-install.ps1 -Version ${{ parameters.version }} -InstallDir "$env:ProgramFiles\dotnet\" -Verbose
18+
& .\dotnet-install.ps1 -Version ${{ parameters.version }} -InstallDir $DotNetRoot -Verbose
1419
& dotnet --list-sdks
1520
displayName: install .NET Core ${{ parameters.version }}
1621
condition: and(succeeded(), eq(variables['agent.os'], 'Windows_NT'))
1722
1823
- bash: >
1924
DOTNET_ROOT=~/.dotnet/ &&
20-
PATH="$DOTNET_ROOT:$PATH" &&
25+
(if [[ "${{ parameters.remove_dotnet }}" == "true" ]] ; then rm -rfv $DOTNET_ROOT; fi) &&
2126
curl -L https://dot.net/v1/dotnet-install.sh > dotnet-install.sh &&
2227
sh dotnet-install.sh --version ${{ parameters.version }} --install-dir $DOTNET_ROOT --verbose &&
28+
PATH="$DOTNET_ROOT:$PATH" &&
2329
dotnet --list-sdks &&
2430
echo "##vso[task.setvariable variable=DOTNET_ROOT]$DOTNET_ROOT" &&
2531
echo "##vso[task.setvariable variable=PATH]$PATH"

0 commit comments

Comments
 (0)