@@ -12,8 +12,6 @@ $PublishDataUrl = "https://raw.githubusercontent.com/dotnet/roslyn/main/eng/conf
1212
1313$binaryLog = if (Test-Path variable:binaryLog) {$binaryLog }else {$false }
1414$nodeReuse = if (Test-Path variable:nodeReuse) {$nodeReuse }else {$false }
15- $bootstrapDir = if (Test-Path variable:bootstrapDir) {$bootstrapDir }else {" " }
16- $bootstrapConfiguration = if (Test-Path variable:bootstrapConfiguration) {$bootstrapConfiguration }else {" Release" }
1715$properties = if (Test-Path variable:properties) {$properties }else {@ () }
1816$originalTemp = $env: TEMP ;
1917
@@ -89,7 +87,11 @@ function Exec-Block([scriptblock]$cmd) {
8987 }
9088}
9189
92- function Exec-CommandCore ([string ]$command , [string ]$commandArgs , [switch ]$useConsole = $true ) {
90+ function Exec-CommandCore ([string ]$command , [string ]$commandArgs , [switch ]$useConsole = $true , [switch ]$echoCommand = $true ) {
91+ if ($echoCommand ) {
92+ Write-Host " $command $commandArgs "
93+ }
94+
9395if ($useConsole ) {
9496$exitCode = Exec- Process$command $commandArgs
9597if ($exitCode -ne 0 ) {
@@ -151,27 +153,39 @@ function Exec-CommandCore([string]$command, [string]$commandArgs, [switch]$useCo
151153# $args = "/p:ManualBuild=true Test.proj"
152154# Exec-Command $msbuild $args
153155#
154- function Exec-Command ([string ]$command , [string ]$commandArgs ) {
155- Exec- CommandCore- command$command - commandArgs$commandargs - useConsole:$false
156- }
157-
158- # Functions exactly like Exec-Command but lets the process re-use the current
159- # console. This means items like colored output will function correctly.
160- #
161- # In general this command should be used in place of
162- # Exec-Command $msbuild $args | Out-Host
163- #
164- function Exec-Console ([string ]$command , [string ]$commandArgs ) {
165- Exec- CommandCore- command$command - commandArgs$commandargs - useConsole:$true
156+ # The -useConsole argument controls if the process should re-use the current
157+ # console for output or return output as a string
158+ function Exec-Command ([string ]$command , [string ]$commandArgs , [switch ]$useConsole = $false , [switch ]$echoCommand = $true ) {
159+ if ($args -ne " " ) {
160+ throw " Extra arguments passed to Exec-Command:$args "
161+ }
162+ Exec- CommandCore- command$command - commandArgs$commandArgs - useConsole:$useConsole - echoCommand:$echoCommand
166163}
167164
168165# Handy function for executing a powershell script in a clean environment with
169166# arguments. Prefer this over & sourcing a script as it will both use a clean
170167# environment and do proper error checking
171- function Exec-Script ([string ]$script , [string ]$scriptArgs = " " ) {
172- Exec- Command" pwsh" " -noprofile -executionPolicy RemoteSigned -file`" $script `" $scriptArgs "
168+ #
169+ # The -useConsole argument controls if the process should re-use the current
170+ # console for output or return output as a string
171+ function Exec-Script ([string ]$script , [string ]$scriptArgs = " " , [switch ]$useConsole = $true , [switch ]$echoCommand = $true ) {
172+ if ($args -ne " " ) {
173+ throw " Extra arguments passed to Exec-Script:$args "
174+ }
175+ Exec- CommandCore- command" pwsh" - commandArgs" -noprofile -executionPolicy RemoteSigned -file`" $script `" $scriptArgs " - useConsole:$useConsole - echoCommand:$echoCommand
173176}
174177
178+ # Handy function for executing a dotnet command without having to track down the
179+ # proper dotnet executable or ensure it's on the path.
180+ function Exec-DotNet ([string ]$commandArgs = " " , [switch ]$useConsole = $true , [switch ]$echoCommand = $true ) {
181+ if ($args -ne " " ) {
182+ throw " Extra arguments passed to Exec-DotNet:$args "
183+ }
184+ $dotnet = Ensure- DotNetSdk
185+ Exec- CommandCore- command$dotnet - commandArgs$commandArgs - useConsole:$useConsole - echoCommand:$echoCommand
186+ }
187+
188+
175189# Ensure the proper .NET Core SDK is available. Returns the location to the dotnet.exe.
176190function Ensure-DotnetSdk () {
177191$dotnetInstallDir = (InitializeDotNetCli- install:$true )
@@ -262,91 +276,6 @@ function Get-PackageDir([string]$name, [string]$version = "") {
262276return $p
263277}
264278
265- # Create a bootstrap build of the compiler. Returns the directory where the bootstrap build
266- # is located.
267- #
268- # Important to not set $script:bootstrapDir here yet as we're actually in the process of
269- # building the bootstrap.
270- function Make-BootstrapBuild ([string ]$bootstrapToolset = " " ) {
271-
272- function Run-MSBuild ([string ]$projectFilePath , [string ]$buildArgs = " " , [string ]$logFileName = " " , [string ]$configuration = $script :configuration ) {
273- # Because we override the C#/VB toolset to build against our LKG package, it is important
274- # that we do not reuse MSBuild nodes from other jobs/builds on the machine. Otherwise,
275- # we'll run into issues such as https://github.com/dotnet/roslyn/issues/6211.
276- # MSBuildAdditionalCommandLineArgs=
277- $args = " /p:TreatWarningsAsErrors=true /nologo /nodeReuse:false /p:Configuration=$configuration /v:m" ;
278-
279- if ($warnAsError ) {
280- $args += " /warnaserror"
281- }
282-
283- if ($runAnalyzers ) {
284- $args += " /p:RunAnalyzersDuringBuild=true"
285- }
286-
287- if ($binaryLog ) {
288- if ($logFileName -eq " " ) {
289- $logFileName = [IO.Path ]::GetFileNameWithoutExtension($projectFilePath )
290- }
291- $logFileName = [IO.Path ]::ChangeExtension($logFileName , " .binlog" )
292- $logFilePath = Join-Path $LogDir $logFileName
293- $args += " /bl:$logFilePath "
294- }
295-
296- if ($officialBuildId ) {
297- $args += " /p:OfficialBuildId=" + $officialBuildId
298- }
299-
300- if ($ci ) {
301- $args += " /p:ContinuousIntegrationBuild=true"
302- }
303-
304- if ($bootstrapDir -ne " " ) {
305- $args += " /p:BootstrapBuildPath=$bootstrapDir "
306- }
307-
308- $args += " $buildArgs "
309- $args += " $projectFilePath "
310- $args += " $properties "
311-
312- $buildTool = InitializeBuildTool
313- Exec- Console$buildTool.Path " $ ( $buildTool.Command ) $args "
314- }
315-
316- Write-Host " Building bootstrap compiler"
317-
318- $dir = Join-Path $ArtifactsDir " Bootstrap"
319- Remove-Item - re$dir - ErrorAction SilentlyContinue
320- Create- Directory$dir
321-
322- if ($bootstrapToolset -eq " " -or $bootstrapToolset -eq " AnyCPU" ) {
323- $projectPath = " src\NuGet\Microsoft.Net.Compilers.Toolset\AnyCpu\Microsoft.Net.Compilers.Toolset.Package.csproj"
324- $packageName = " Microsoft.Net.Compilers.Toolset"
325- }
326- elseif ($bootstrapToolset -eq " Framework" ) {
327- $projectPath = " src\NuGet\Microsoft.Net.Compilers.Toolset\Framework\Microsoft.Net.Compilers.Toolset.Framework.Package.csproj"
328- $packageName = " Microsoft.Net.Compilers.Toolset.Framework"
329- }
330- else {
331- throw " Unsupported bootstrap toolset$bootstrapToolset "
332- }
333-
334- Run- MSBuild$projectPath " /restore /t:Pack /p:RoslynEnforceCodeStyle=false /p:RunAnalyzersDuringBuild=false /p:DotNetUseShippingVersions=true /p:InitialDefineConstants=BOOTSTRAP /p:PackageOutputPath=`" $dir `" /p:EnableNgenOptimization=false /p:PublishWindowsPdb=false" - logFileName" Bootstrap" - configuration$bootstrapConfiguration
335- $packageFile = Get-ChildItem - Path$dir - Filter" $packageName .*.nupkg"
336- Unzip (Join-Path $dir $packageFile.Name )$dir
337-
338- Write-Host " Cleaning Bootstrap compiler artifacts"
339- Run- MSBuild$projectPath " /t:Clean" - logFileName" BootstrapClean"
340-
341- # Work around NuGet bug that doesn't correctly re-generate our project.assets.json files.
342- # Deleting everything forces a regen
343- # https://github.com/NuGet/Home/issues/12437
344- Remove-Item - Recurse- Force (Join-Path $ArtifactsDir " bin" )
345- Remove-Item - Recurse- Force (Join-Path $ArtifactsDir " obj" )
346-
347- return $dir
348- }
349-
350279function Subst-TempDir () {
351280if ($ci ) {
352281 Exec- Command" subst" " T:$TempDir "