11function 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
2858function 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
4473title SDK Build ($RepoRoot )
4574set DOTNET_MULTILEVEL_LOOKUP=0
@@ -56,11 +85,11 @@ set DOTNET_ADD_GLOBAL_TOOLS_TO_PATH=0
5685DOSKEY 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
121147function 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
136163function 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
168193InitializeCustomSDKToolset
0 commit comments