@@ -184,6 +184,7 @@ param(
184184 [Alias (' v' )]
185185 [string ]$Verbosity = ' minimal' ,
186186 [switch ]$DumpProcesses , # Capture all running processes and dump them to a file.
187+ [string ]$msbuildEngine = ' dotnet' ,
187188
188189 # Other lifecycle targets
189190 [switch ]$Help , # Show help
@@ -288,24 +289,20 @@ if ($RuntimeSourceFeed -or $RuntimeSourceFeedKey) {
288289}
289290
290291# Split build categories between dotnet msbuild and desktop msbuild. Use desktop msbuild as little as possible.
291- [string []]$dotnetBuildArguments = $MSBuildArguments
292+ [string []]$dotnetBuildArguments = ' '
293+ [string []]$MSBuildOnlyArguments = ' '
294+
292295if ($All ) { $dotnetBuildArguments += ' /p:BuildAllProjects=true' }
293- if ($Projects ) {
294- if ($BuildNative ) {
295- $MSBuildArguments += " /p:ProjectToBuild=$Projects "
296- } else {
297- $dotnetBuildArguments += " /p:ProjectToBuild=$Projects "
298- }
299- }
296+ if ($Projects ) { $MSBuildArguments += " /p:ProjectToBuild=$Projects " }
300297
301- if ($NoBuildInstallers ) { $MSBuildArguments += " /p:BuildInstallers=false" ; $BuildInstallers = $false }
302- if ($BuildInstallers ) { $MSBuildArguments += " /p:BuildInstallers=true" }
298+ if ($NoBuildInstallers ) { $MSBuildOnlyArguments += " /p:BuildInstallers=false" ; $BuildInstallers = $false }
299+ if ($BuildInstallers ) { $MSBuildOnlyArguments += " /p:BuildInstallers=true" }
303300
304301# Build native projects by default unless -NoBuildNative was specified.
305302$specifiedBuildNative = $BuildNative
306303$BuildNative = $true
307- if ($NoBuildNative ) { $MSBuildArguments += " /p:BuildNative=false" ; $BuildNative = $false }
308- if ($BuildNative ) { $MSBuildArguments += " /p:BuildNative=true" }
304+ if ($NoBuildNative ) { $MSBuildOnlyArguments += " /p:BuildNative=false" ; $BuildNative = $false }
305+ if ($BuildNative ) { $MSBuildOnlyArguments += " /p:BuildNative=true" }
309306
310307if ($NoBuildJava ) { $dotnetBuildArguments += " /p:BuildJava=false" ; $BuildJava = $false }
311308if ($BuildJava ) { $dotnetBuildArguments += " /p:BuildJava=true" }
@@ -317,23 +314,24 @@ if ($BuildNodeJS) { $dotnetBuildArguments += "/p:BuildNodeJSUnlessSourcebuild=tr
317314# Don't bother with two builds if just one will build everything. Ignore super-weird cases like
318315# "-Projects ... -NoBuildJava -NoBuildManaged -NoBuildNodeJS". An empty `./build.ps1` command will build both
319316# managed and native projects.
320- $performDesktopBuild = $BuildInstallers -or $BuildNative
321- $performDotnetBuild = $BuildJava -or $BuildManaged -or $BuildNodeJS -or `
317+
318+ # If -msbuildEngine vs is explicitly passed in, use desktop msbuild only.
319+ # This is necessary for one-shot builds like within the VMR.
320+
321+ $performDesktopBuild = $BuildInstallers -or $BuildNative -or $msbuildEngine -eq ' vs'
322+ $performDotnetBuild = $msBuildEngine -ne ' vs' -and ($BuildJava -or $BuildManaged -or $BuildNodeJS -or `
322323 ($All -and -not ($NoBuildJava -and $NoBuildManaged -and $NoBuildNodeJS )) -or `
323- ($Projects -and -not ($BuildInstallers -or $specifiedBuildNative ))
324+ ($Projects -and -not ($BuildInstallers -or $specifiedBuildNative )))
324325
325326# Initialize global variables need to be set before the import of Arcade is imported
326327$restore = $RunRestore
327328
328- # Though VS Code may indicate $nodeReuse and $msbuildEngine are unused, tools.ps1 uses them.
329+ # Though VS Code may indicate $nodeReuse is unused, tools.ps1 uses them.
329330
330331# Disable node reuse - Workaround perpetual issues in node reuse and custom task assemblies
331332$nodeReuse = $false
332333$env: MSBUILDDISABLENODEREUSE = 1
333334
334- # Use `dotnet msbuild` by default
335- $msbuildEngine = ' dotnet'
336-
337335# Ensure passing neither -bl nor -nobl on CI avoids errors in tools.ps1. This is needed because both parameters are
338336# $false by default i.e. they always exist. (We currently avoid binary logs but that is made visible in the YAML.)
339337if ($CI -and -not $excludeCIBinarylog ) {
@@ -414,12 +412,17 @@ if ($BinaryLog) {
414412 $bl = GetMSBuildBinaryLogCommandLineArgument($MSBuildArguments )
415413 if (-not $bl ) {
416414 $dotnetBuildArguments += " /bl:" + (Join-Path $LogDir " Build.binlog" )
417- $MSBuildArguments += " /bl:" + (Join-Path $LogDir " Build.native.binlog" )
415+
416+ # When running both builds, use a different binary log path for the desktop msbuild.
417+ if ($performDesktopBuild -and $performDotnetBuild ) {
418+ $MSBuildOnlyArguments += " /bl:" + (Join-Path $LogDir " Build.native.binlog" )
419+ }
420+
418421 $ToolsetBuildArguments += " /bl:" + (Join-Path $LogDir " Build.repotasks.binlog" )
419422 } else {
420423 # Use a different binary log path when running desktop msbuild if doing both builds.
421424 if ($performDesktopBuild -and $performDotnetBuild ) {
422- $MSBuildArguments += " /bl:" + [System.IO.Path ]::ChangeExtension($bl , " native.binlog" )
425+ $MSBuildOnlyArguments += " /bl:" + [System.IO.Path ]::ChangeExtension($bl , " native.binlog" )
423426 }
424427
425428 $ToolsetBuildArguments += " /bl:" + [System.IO.Path ]::ChangeExtension($bl , " repotasks.binlog" )
@@ -478,15 +481,20 @@ try {
478481 Remove-Item variable:global:_BuildTool - ErrorAction Ignore
479482 $msbuildEngine = ' vs'
480483
481- MSBuild $toolsetBuildProj / p:RepoRoot= $RepoRoot @MSBuildArguments
484+ # When running with desktop msbuild only, append the dotnet build specific arguments.
485+ if (-not $performDotnetBuild ) {
486+ $MSBuildOnlyArguments += $dotnetBuildArguments
487+ }
488+
489+ MSBuild $toolsetBuildProj / p:RepoRoot= $RepoRoot @MSBuildArguments @MSBuildOnlyArguments
482490 }
483491
484492 if ($performDotnetBuild ) {
485493 Write-Host
486494 Remove-Item variable:global:_BuildTool - ErrorAction Ignore
487495 $msbuildEngine = ' dotnet'
488496
489- MSBuild $toolsetBuildProj / p:RepoRoot= $RepoRoot @dotnetBuildArguments
497+ MSBuild $toolsetBuildProj / p:RepoRoot= $RepoRoot @MSBuildArguments @ dotnetBuildArguments
490498 }
491499 }
492500}
0 commit comments