Skip to content

Commit 1265011

Browse files
authored
.NET SDK release/dnup branch build uses dotnetup to download core .NET runtimes (#52695)
Failures in the SDK CI are due to known Pack issues, unrelated to dotnetup
2 parents a903f93 + 5eadd92 commit 1265011

File tree

11 files changed

+805
-142
lines changed

11 files changed

+805
-142
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ cmake/
4040
# Helix payload
4141
.dotnet.payload
4242

43+
# dotnetup build output
44+
eng/dotnetup/
45+
4346
# MSBuild Logs
4447
**/MSBuild_Logs/MSBuild_pid-*.failure.txt
4548

eng/restore-toolset.ps1

Lines changed: 134 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,74 @@
11
function InitializeCustomSDKToolset {
2-
if ($env:TestFullMSBuild -eq "true") {
3-
$env:DOTNET_SDK_TEST_MSBUILD_PATH = InitializeVisualStudioMSBuild -install:$true -vsRequirements:$GlobalJson.tools.'vs-opt'
4-
Write-Host "INFO: Tests will run against full MSBuild in $env:DOTNET_SDK_TEST_MSBUILD_PATH"
5-
}
6-
7-
if (-not $restore) {
8-
return
9-
}
10-
11-
# The following frameworks and tools are used only for testing.
12-
# Do not attempt to install them when building in the VMR.
13-
if ($fromVmr) {
14-
return
15-
}
16-
17-
$cli = InitializeDotnetCli -install:$true
18-
InstallDotNetSharedFramework "6.0.0"
19-
InstallDotNetSharedFramework "7.0.0"
20-
InstallDotNetSharedFramework "8.0.0"
21-
InstallDotNetSharedFramework "9.0.0"
22-
23-
CreateBuildEnvScripts
24-
CreateVSShortcut
25-
InstallNuget
2+
if ($env:TestFullMSBuild -eq "true") {
3+
$env:DOTNET_SDK_TEST_MSBUILD_PATH = InitializeVisualStudioMSBuild -install:$true -vsRequirements:$GlobalJson.tools.'vs-opt'
4+
Write-Host "INFO: Tests will run against full MSBuild in $env:DOTNET_SDK_TEST_MSBUILD_PATH"
5+
}
6+
7+
if (-not $restore) {
8+
return
9+
}
10+
11+
# The following frameworks and tools are used only for testing.
12+
# Do not attempt to install them when building in the VMR.
13+
if ($fromVmr) {
14+
return
15+
}
16+
17+
$cli = InitializeDotnetCli -install:$true
18+
19+
# Build dotnetup if not already present (needs SDK to be installed first)
20+
EnsureDotnetupBuilt
21+
22+
InstallDotNetSharedFramework "6.0"
23+
InstallDotNetSharedFramework "7.0"
24+
InstallDotNetSharedFramework "8.0"
25+
InstallDotNetSharedFramework "9.0"
26+
27+
CreateBuildEnvScripts
28+
CreateVSShortcut
29+
InstallNuget
30+
}
31+
32+
function EnsureDotnetupBuilt {
33+
$dotnetupExe = Join-Path $PSScriptRoot "dotnetup\dotnetup.exe"
34+
35+
if (!(Test-Path $dotnetupExe)) {
36+
Write-Host "Building dotnetup..."
37+
$dotnetupProject = Join-Path $RepoRoot "src\Installer\dotnetup\dotnetup.csproj"
38+
$dotnetupOutDir = Join-Path $PSScriptRoot "dotnetup"
39+
40+
# Determine RID based on architecture
41+
$rid = if ([System.Runtime.InteropServices.RuntimeInformation]::ProcessArchitecture -eq [System.Runtime.InteropServices.Architecture]::Arm64) {
42+
"win-arm64"
43+
}
44+
else {
45+
"win-x64"
46+
}
47+
48+
& (Join-Path $env:DOTNET_INSTALL_DIR 'dotnet.exe') publish $dotnetupProject -c Release -r $rid -o $dotnetupOutDir
49+
50+
if ($lastExitCode -ne 0) {
51+
throw "Failed to build dotnetup (exit code '$lastExitCode')."
52+
}
53+
54+
Write-Host "dotnetup built successfully"
55+
}
2656
}
2757

2858
function InstallNuGet {
29-
$NugetInstallDir = Join-Path $ArtifactsDir ".nuget"
30-
$NugetExe = Join-Path $NugetInstallDir "nuget.exe"
59+
$NugetInstallDir = Join-Path $ArtifactsDir ".nuget"
60+
$NugetExe = Join-Path $NugetInstallDir "nuget.exe"
3161

32-
if (!(Test-Path -Path $NugetExe)) {
33-
Create-Directory $NugetInstallDir
34-
Invoke-WebRequest "https://dist.nuget.org/win-x86-commandline/latest/nuget.exe" -UseBasicParsing -OutFile $NugetExe
35-
}
62+
if (!(Test-Path -Path $NugetExe)) {
63+
Create-Directory $NugetInstallDir
64+
Invoke-WebRequest "https://dist.nuget.org/win-x86-commandline/latest/nuget.exe" -UseBasicParsing -OutFile $NugetExe
65+
}
3666
}
3767

38-
function CreateBuildEnvScripts()
39-
{
40-
Create-Directory $ArtifactsDir
41-
$scriptPath = Join-Path $ArtifactsDir "sdk-build-env.bat"
42-
$scriptContents = @"
68+
function CreateBuildEnvScripts() {
69+
Create-Directory $ArtifactsDir
70+
$scriptPath = Join-Path $ArtifactsDir "sdk-build-env.bat"
71+
$scriptContents = @"
4372
@echo off
4473
title SDK Build ($RepoRoot)
4574
set DOTNET_MULTILEVEL_LOOKUP=0
@@ -56,11 +85,11 @@ set DOTNET_ADD_GLOBAL_TOOLS_TO_PATH=0
5685
DOSKEY killdotnet=taskkill /F /IM dotnet.exe /T ^& taskkill /F /IM VSTest.Console.exe /T ^& taskkill /F /IM msbuild.exe /T
5786
"@
5887

59-
Out-File -FilePath $scriptPath -InputObject $scriptContents -Encoding ASCII
88+
Out-File -FilePath $scriptPath -InputObject $scriptContents -Encoding ASCII
6089

61-
Create-Directory $ArtifactsDir
62-
$scriptPath = Join-Path $ArtifactsDir "sdk-build-env.ps1"
63-
$scriptContents = @"
90+
Create-Directory $ArtifactsDir
91+
$scriptPath = Join-Path $ArtifactsDir "sdk-build-env.ps1"
92+
$scriptContents = @"
6493
`$host.ui.RawUI.WindowTitle = "SDK Build ($RepoRoot)"
6594
`$env:DOTNET_MULTILEVEL_LOOKUP=0
6695
# https://aka.ms/vs/unsigned-dotnet-debugger-lib
@@ -80,89 +109,85 @@ function killdotnet {
80109
}
81110
"@
82111

83-
Out-File -FilePath $scriptPath -InputObject $scriptContents -Encoding ASCII
112+
Out-File -FilePath $scriptPath -InputObject $scriptContents -Encoding ASCII
84113
}
85114

86-
function CreateVSShortcut()
87-
{
88-
# https://github.com/microsoft/vswhere/wiki/Installing
89-
$installerPath = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer"
90-
if(-Not (Test-Path -Path $installerPath))
91-
{
92-
return
93-
}
94-
95-
$versionFilePath = Join-Path $RepoRoot 'src\Layout\redist\minimumMSBuildVersion'
96-
# Gets the first digit (ex. 17) and appends '.0' to it.
97-
$vsMajorVersion = "$(((Get-Content $versionFilePath).Split('.'))[0]).0"
98-
$devenvPath = (& "$installerPath\vswhere.exe" -all -prerelease -latest -version $vsMajorVersion -find Common7\IDE\devenv.exe) | Select-Object -First 1
99-
if(-Not $devenvPath)
100-
{
101-
return
102-
}
103-
104-
$scriptPath = Join-Path $ArtifactsDir 'sdk-build-env.ps1'
105-
$slnPath = Join-Path $RepoRoot 'sdk.slnx'
106-
$commandToLaunch = "& '$scriptPath'; & '$devenvPath' '$slnPath'"
107-
$powershellPath = '%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe'
108-
$shortcutPath = Join-Path $ArtifactsDir 'VS with sdk.slnx.lnk'
109-
110-
# https://stackoverflow.com/a/9701907/294804
111-
# https://learn.microsoft.com/en-us/troubleshoot/windows-client/admin-development/create-desktop-shortcut-with-wsh
112-
$wsShell = New-Object -ComObject WScript.Shell
113-
$shortcut = $wsShell.CreateShortcut($shortcutPath)
114-
$shortcut.TargetPath = $powershellPath
115-
$shortcut.Arguments = "-WindowStyle Hidden -ExecutionPolicy Bypass -Command ""$commandToLaunch"""
116-
$shortcut.IconLocation = $devenvPath
117-
$shortcut.WindowStyle = 7 # Minimized
118-
$shortcut.Save()
115+
function CreateVSShortcut() {
116+
# https://github.com/microsoft/vswhere/wiki/Installing
117+
$installerPath = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer"
118+
if (-Not (Test-Path -Path $installerPath)) {
119+
return
120+
}
121+
122+
$versionFilePath = Join-Path $RepoRoot 'src\Layout\redist\minimumMSBuildVersion'
123+
# Gets the first digit (ex. 17) and appends '.0' to it.
124+
$vsMajorVersion = "$(((Get-Content $versionFilePath).Split('.'))[0]).0"
125+
$devenvPath = (& "$installerPath\vswhere.exe" -all -prerelease -latest -version $vsMajorVersion -find Common7\IDE\devenv.exe) | Select-Object -First 1
126+
if (-Not $devenvPath) {
127+
return
128+
}
129+
130+
$scriptPath = Join-Path $ArtifactsDir 'sdk-build-env.ps1'
131+
$slnPath = Join-Path $RepoRoot 'sdk.slnx'
132+
$commandToLaunch = "& '$scriptPath'; & '$devenvPath' '$slnPath'"
133+
$powershellPath = '%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe'
134+
$shortcutPath = Join-Path $ArtifactsDir 'VS with sdk.slnx.lnk'
135+
136+
# https://stackoverflow.com/a/9701907/294804
137+
# https://learn.microsoft.com/en-us/troubleshoot/windows-client/admin-development/create-desktop-shortcut-with-wsh
138+
$wsShell = New-Object -ComObject WScript.Shell
139+
$shortcut = $wsShell.CreateShortcut($shortcutPath)
140+
$shortcut.TargetPath = $powershellPath
141+
$shortcut.Arguments = "-WindowStyle Hidden -ExecutionPolicy Bypass -Command ""$commandToLaunch"""
142+
$shortcut.IconLocation = $devenvPath
143+
$shortcut.WindowStyle = 7 # Minimized
144+
$shortcut.Save()
119145
}
120146

121147
function InstallDotNetSharedFramework([string]$version) {
122-
$dotnetRoot = $env:DOTNET_INSTALL_DIR
123-
$fxDir = Join-Path $dotnetRoot "shared\Microsoft.NETCore.App\$version"
148+
$dotnetRoot = $env:DOTNET_INSTALL_DIR
149+
$fxDir = Join-Path $dotnetRoot "shared\Microsoft.NETCore.App\$version"
150+
151+
if (!(Test-Path $fxDir)) {
152+
$dotnetupExe = Join-Path $PSScriptRoot "dotnetup\dotnetup.exe"
124153

125-
if (!(Test-Path $fxDir)) {
126-
$installScript = GetDotNetInstallScript $dotnetRoot
127-
& $installScript -Version $version -InstallDir $dotnetRoot -Runtime "dotnet" -SkipNonVersionedFiles
154+
& $dotnetupExe runtime install "$version" --install-path $dotnetRoot --no-progress --set-default-install false
128155

129-
if($lastExitCode -ne 0) {
130-
throw "Failed to install shared Framework $version to '$dotnetRoot' (exit code '$lastExitCode')."
156+
if ($lastExitCode -ne 0) {
157+
throw "Failed to install shared Framework $version to '$dotnetRoot' using dotnetup (exit code '$lastExitCode')."
158+
}
131159
}
132-
}
133160
}
134161

135162
# Let's clear out the stage-zero folders that map to the current runtime to keep stage 2 clean
136163
function CleanOutStage0ToolsetsAndRuntimes {
137-
$GlobalJson = Get-Content -Raw -Path (Join-Path $RepoRoot 'global.json') | ConvertFrom-Json
138-
$dotnetSdkVersion = $GlobalJson.tools.dotnet
139-
$dotnetRoot = $env:DOTNET_INSTALL_DIR
140-
$versionPath = Join-Path $dotnetRoot '.version'
141-
$aspnetRuntimePath = [IO.Path]::Combine( $dotnetRoot, 'shared' ,'Microsoft.AspNetCore.App')
142-
$coreRuntimePath = [IO.Path]::Combine( $dotnetRoot, 'shared' ,'Microsoft.NETCore.App')
143-
$wdRuntimePath = [IO.Path]::Combine( $dotnetRoot, 'shared', 'Microsoft.WindowsDesktop.App')
144-
$sdkPath = Join-Path $dotnetRoot 'sdk'
145-
$majorVersion = $dotnetSdkVersion.Substring(0,1)
146-
147-
if (Test-Path($versionPath)) {
148-
$lastInstalledSDK = Get-Content -Raw -Path ($versionPath)
149-
if ($lastInstalledSDK -ne $dotnetSdkVersion)
150-
{
151-
$dotnetSdkVersion | Out-File -FilePath $versionPath -NoNewline
152-
Remove-Item (Join-Path $aspnetRuntimePath "$majorVersion.*") -Recurse
153-
Remove-Item (Join-Path $coreRuntimePath "$majorVersion.*") -Recurse
154-
Remove-Item (Join-Path $wdRuntimePath "$majorVersion.*") -Recurse
155-
Remove-Item (Join-Path $sdkPath "*") -Recurse
156-
Remove-Item (Join-Path $dotnetRoot "packs") -Recurse
157-
Remove-Item (Join-Path $dotnetRoot "sdk-manifests") -Recurse
158-
Remove-Item (Join-Path $dotnetRoot "templates") -Recurse
159-
throw "Installed a new SDK, deleting existing shared frameworks and sdk folders. Please rerun build"
164+
$GlobalJson = Get-Content -Raw -Path (Join-Path $RepoRoot 'global.json') | ConvertFrom-Json
165+
$dotnetSdkVersion = $GlobalJson.tools.dotnet
166+
$dotnetRoot = $env:DOTNET_INSTALL_DIR
167+
$versionPath = Join-Path $dotnetRoot '.version'
168+
$aspnetRuntimePath = [IO.Path]::Combine( $dotnetRoot, 'shared' , 'Microsoft.AspNetCore.App')
169+
$coreRuntimePath = [IO.Path]::Combine( $dotnetRoot, 'shared' , 'Microsoft.NETCore.App')
170+
$wdRuntimePath = [IO.Path]::Combine( $dotnetRoot, 'shared', 'Microsoft.WindowsDesktop.App')
171+
$sdkPath = Join-Path $dotnetRoot 'sdk'
172+
$majorVersion = $dotnetSdkVersion.Substring(0, 1)
173+
174+
if (Test-Path($versionPath)) {
175+
$lastInstalledSDK = Get-Content -Raw -Path ($versionPath)
176+
if ($lastInstalledSDK -ne $dotnetSdkVersion) {
177+
$dotnetSdkVersion | Out-File -FilePath $versionPath -NoNewline
178+
Remove-Item (Join-Path $aspnetRuntimePath "$majorVersion.*") -Recurse
179+
Remove-Item (Join-Path $coreRuntimePath "$majorVersion.*") -Recurse
180+
Remove-Item (Join-Path $wdRuntimePath "$majorVersion.*") -Recurse
181+
Remove-Item (Join-Path $sdkPath "*") -Recurse
182+
Remove-Item (Join-Path $dotnetRoot "packs") -Recurse
183+
Remove-Item (Join-Path $dotnetRoot "sdk-manifests") -Recurse
184+
Remove-Item (Join-Path $dotnetRoot "templates") -Recurse
185+
throw "Installed a new SDK, deleting existing shared frameworks and sdk folders. Please rerun build"
186+
}
187+
}
188+
else {
189+
$dotnetSdkVersion | Out-File -FilePath $versionPath -NoNewline
160190
}
161-
}
162-
else
163-
{
164-
$dotnetSdkVersion | Out-File -FilePath $versionPath -NoNewline
165-
}
166191
}
167192

168193
InitializeCustomSDKToolset

eng/restore-toolset.sh

Lines changed: 48 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,29 +21,69 @@ function InitializeCustomSDKToolset {
2121

2222
InitializeDotNetCli true
2323

24-
InstallDotNetSharedFramework "6.0.0"
25-
InstallDotNetSharedFramework "7.0.0"
26-
InstallDotNetSharedFramework "8.0.0"
27-
InstallDotNetSharedFramework "9.0.0"
24+
# Build dotnetup if not already present (needs SDK to be installed first)
25+
EnsureDotnetupBuilt
26+
27+
InstallDotNetSharedFramework "6.0"
28+
InstallDotNetSharedFramework "7.0"
29+
InstallDotNetSharedFramework "8.0"
30+
InstallDotNetSharedFramework "9.0"
2831

2932
CreateBuildEnvScript
3033
}
3134

35+
# Builds dotnetup if the executable doesn't exist
36+
function EnsureDotnetupBuilt {
37+
local script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
38+
local dotnetup_dir="$script_dir/dotnetup"
39+
local dotnetup_exe="$dotnetup_dir/dotnetup"
40+
41+
if [[ ! -f "$dotnetup_exe" ]]; then
42+
echo "Building dotnetup..."
43+
local dotnetup_project="$repo_root/src/Installer/dotnetup/dotnetup.csproj"
44+
45+
# Determine RID based on OS
46+
local rid
47+
if [[ "$(uname)" == "Darwin" ]]; then
48+
if [[ "$(uname -m)" == "arm64" ]]; then
49+
rid="osx-arm64"
50+
else
51+
rid="osx-x64"
52+
fi
53+
else
54+
if [[ "$(uname -m)" == "aarch64" ]]; then
55+
rid="linux-arm64"
56+
else
57+
rid="linux-x64"
58+
fi
59+
fi
60+
61+
"$DOTNET_INSTALL_DIR/dotnet" publish "$dotnetup_project" -c Release -r "$rid" -o "$dotnetup_dir"
62+
63+
if [[ $? -ne 0 ]]; then
64+
echo "Failed to build dotnetup."
65+
ExitWithExitCode 1
66+
fi
67+
68+
echo "dotnetup built successfully"
69+
fi
70+
}
71+
3272
# Installs additional shared frameworks for testing purposes
3373
function InstallDotNetSharedFramework {
3474
local version=$1
3575
local dotnet_root=$DOTNET_INSTALL_DIR
3676
local fx_dir="$dotnet_root/shared/Microsoft.NETCore.App/$version"
3777

3878
if [[ ! -d "$fx_dir" ]]; then
39-
GetDotNetInstallScript "$dotnet_root"
40-
local install_script=$_GetDotNetInstallScript
79+
local script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
80+
local dotnetup_exe="$script_dir/dotnetup/dotnetup"
4181

42-
bash "$install_script" --version $version --install-dir "$dotnet_root" --runtime "dotnet" --skip-non-versioned-files
82+
"$dotnetup_exe" runtime install "$version" --install-path "$dotnet_root" --no-progress --set-default-install false
4383
local lastexitcode=$?
4484

4585
if [[ $lastexitcode != 0 ]]; then
46-
echo "Failed to install Shared Framework $version to '$dotnet_root' (exit code '$lastexitcode')."
86+
echo "Failed to install Shared Framework $version to '$dotnet_root' using dotnetup (exit code '$lastexitcode')."
4787
ExitWithExitCode $lastexitcode
4888
fi
4989
fi

0 commit comments

Comments
 (0)