diff --git a/eng/build.ps1 b/eng/build.ps1 index 3696fe11e0df3..86f4a4f67f151 100644 --- a/eng/build.ps1 +++ b/eng/build.ps1 @@ -184,6 +184,7 @@ param( [Alias('v')] [string]$Verbosity = 'minimal', [switch]$DumpProcesses, # Capture all running processes and dump them to a file. + [string]$msbuildEngine = 'dotnet', # Other lifecycle targets [switch]$Help, # Show help @@ -288,24 +289,20 @@ if ($RuntimeSourceFeed -or $RuntimeSourceFeedKey) { } # Split build categories between dotnet msbuild and desktop msbuild. Use desktop msbuild as little as possible. -[string[]]$dotnetBuildArguments = $MSBuildArguments +[string[]]$dotnetBuildArguments = '' +[string[]]$MSBuildOnlyArguments = '' + if ($All) { $dotnetBuildArguments += '/p:BuildAllProjects=true' } -if ($Projects) { - if ($BuildNative) { - $MSBuildArguments += "/p:ProjectToBuild=$Projects" - } else { - $dotnetBuildArguments += "/p:ProjectToBuild=$Projects" - } -} +if ($Projects) { $MSBuildArguments += "/p:ProjectToBuild=$Projects" } -if ($NoBuildInstallers) { $MSBuildArguments += "/p:BuildInstallers=false"; $BuildInstallers = $false } -if ($BuildInstallers) { $MSBuildArguments += "/p:BuildInstallers=true" } +if ($NoBuildInstallers) { $MSBuildOnlyArguments += "/p:BuildInstallers=false"; $BuildInstallers = $false } +if ($BuildInstallers) { $MSBuildOnlyArguments += "/p:BuildInstallers=true" } # Build native projects by default unless -NoBuildNative was specified. $specifiedBuildNative = $BuildNative $BuildNative = $true -if ($NoBuildNative) { $MSBuildArguments += "/p:BuildNative=false"; $BuildNative = $false } -if ($BuildNative) { $MSBuildArguments += "/p:BuildNative=true"} +if ($NoBuildNative) { $MSBuildOnlyArguments += "/p:BuildNative=false"; $BuildNative = $false } +if ($BuildNative) { $MSBuildOnlyArguments += "/p:BuildNative=true"} if ($NoBuildJava) { $dotnetBuildArguments += "/p:BuildJava=false"; $BuildJava = $false } if ($BuildJava) { $dotnetBuildArguments += "/p:BuildJava=true" } @@ -317,23 +314,24 @@ if ($BuildNodeJS) { $dotnetBuildArguments += "/p:BuildNodeJSUnlessSourcebuild=tr # Don't bother with two builds if just one will build everything. Ignore super-weird cases like # "-Projects ... -NoBuildJava -NoBuildManaged -NoBuildNodeJS". An empty `./build.ps1` command will build both # managed and native projects. -$performDesktopBuild = $BuildInstallers -or $BuildNative -$performDotnetBuild = $BuildJava -or $BuildManaged -or $BuildNodeJS -or ` + +# If -msbuildEngine vs is explicitly passed in, use desktop msbuild only. +# This is necessary for one-shot builds like within the VMR. + +$performDesktopBuild = $BuildInstallers -or $BuildNative -or $msbuildEngine -eq 'vs' +$performDotnetBuild = $msBuildEngine -ne 'vs' -and ($BuildJava -or $BuildManaged -or $BuildNodeJS -or ` ($All -and -not ($NoBuildJava -and $NoBuildManaged -and $NoBuildNodeJS)) -or ` - ($Projects -and -not ($BuildInstallers -or $specifiedBuildNative)) + ($Projects -and -not ($BuildInstallers -or $specifiedBuildNative))) # Initialize global variables need to be set before the import of Arcade is imported $restore = $RunRestore -# Though VS Code may indicate $nodeReuse and $msbuildEngine are unused, tools.ps1 uses them. +# Though VS Code may indicate $nodeReuse is unused, tools.ps1 uses them. # Disable node reuse - Workaround perpetual issues in node reuse and custom task assemblies $nodeReuse = $false $env:MSBUILDDISABLENODEREUSE=1 -# Use `dotnet msbuild` by default -$msbuildEngine = 'dotnet' - # Ensure passing neither -bl nor -nobl on CI avoids errors in tools.ps1. This is needed because both parameters are # $false by default i.e. they always exist. (We currently avoid binary logs but that is made visible in the YAML.) if ($CI -and -not $excludeCIBinarylog) { @@ -414,12 +412,17 @@ if ($BinaryLog) { $bl = GetMSBuildBinaryLogCommandLineArgument($MSBuildArguments) if (-not $bl) { $dotnetBuildArguments += "/bl:" + (Join-Path $LogDir "Build.binlog") - $MSBuildArguments += "/bl:" + (Join-Path $LogDir "Build.native.binlog") + + # When running both builds, use a different binary log path for the desktop msbuild. + if ($performDesktopBuild -and $performDotnetBuild) { + $MSBuildOnlyArguments += "/bl:" + (Join-Path $LogDir "Build.native.binlog") + } + $ToolsetBuildArguments += "/bl:" + (Join-Path $LogDir "Build.repotasks.binlog") } else { # Use a different binary log path when running desktop msbuild if doing both builds. if ($performDesktopBuild -and $performDotnetBuild) { - $MSBuildArguments += "/bl:" + [System.IO.Path]::ChangeExtension($bl, "native.binlog") + $MSBuildOnlyArguments += "/bl:" + [System.IO.Path]::ChangeExtension($bl, "native.binlog") } $ToolsetBuildArguments += "/bl:" + [System.IO.Path]::ChangeExtension($bl, "repotasks.binlog") @@ -478,7 +481,12 @@ try { Remove-Item variable:global:_BuildTool -ErrorAction Ignore $msbuildEngine = 'vs' - MSBuild $toolsetBuildProj /p:RepoRoot=$RepoRoot @MSBuildArguments + # When running with desktop msbuild only, append the dotnet build specific arguments. + if (-not $performDotnetBuild) { + $MSBuildOnlyArguments += $dotnetBuildArguments + } + + MSBuild $toolsetBuildProj /p:RepoRoot=$RepoRoot @MSBuildArguments @MSBuildOnlyArguments } if ($performDotnetBuild) { @@ -486,7 +494,7 @@ try { Remove-Item variable:global:_BuildTool -ErrorAction Ignore $msbuildEngine = 'dotnet' - MSBuild $toolsetBuildProj /p:RepoRoot=$RepoRoot @dotnetBuildArguments + MSBuild $toolsetBuildProj /p:RepoRoot=$RepoRoot @MSBuildArguments @dotnetBuildArguments } } }