Skip to content

Commit b2270bb

Browse files
committed
Make dotnet msbuild the default on Windows too
- add step using desktop `msbuild` when native builds may be involved - `-All` (without `-NoBuildNative`), `-BuildNative` or `-BuildInstallers` run this step - but `-ForceCoreMsbuild` unconditionally skips this step nits: - add binary log for RepoTasks build (echoes the `dotnet msbuild` command) if `$BinaryLog` - add blank lines between build steps
1 parent bad6e32 commit b2270bb

File tree

1 file changed

+55
-26
lines changed

1 file changed

+55
-26
lines changed

build.ps1

Lines changed: 55 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,8 @@ param(
146146

147147
[switch]$NoBuildRepoTasks,
148148

149-
# By default, Windows builds will use MSBuild.exe. Passing this will force the build to run on
150-
# dotnet.exe instead, which may cause issues if you invoke build on a project unsupported by
151-
# MSBuild for .NET Core
149+
# Disable pre-build of C++ code in x64 (default) and x86 builds. Affects -All and -Projects handling and causes
150+
# -BuildInstallers and -BuildNative to be ignored.
152151
[switch]$ForceCoreMsbuild,
153152

154153
# Diagnostics
@@ -187,10 +186,6 @@ if ($DumpProcesses -or $CI) {
187186
}
188187

189188
# Project selection
190-
if ($All) {
191-
$MSBuildArguments += '/p:BuildAllProjects=true'
192-
}
193-
194189
if ($Projects) {
195190
if (![System.IO.Path]::IsPathRooted($Projects))
196191
{
@@ -227,20 +222,8 @@ if ($BuildManaged -or ($All -and (-not $NoBuildManaged))) {
227222
}
228223
}
229224

230-
if ($BuildInstallers) { $MSBuildArguments += "/p:BuildInstallers=true" }
231-
if ($BuildManaged) { $MSBuildArguments += "/p:BuildManaged=true" }
232-
if ($BuildNative) { $MSBuildArguments += "/p:BuildNative=true" }
233-
if ($BuildNodeJS) { $MSBuildArguments += "/p:BuildNodeJS=true" }
234-
if ($BuildJava) { $MSBuildArguments += "/p:BuildJava=true" }
235-
236225
if ($NoBuildDeps) { $MSBuildArguments += "/p:BuildProjectReferences=false" }
237226

238-
if ($NoBuildInstallers) { $MSBuildArguments += "/p:BuildInstallers=false" }
239-
if ($NoBuildManaged) { $MSBuildArguments += "/p:BuildManaged=false" }
240-
if ($NoBuildNative) { $MSBuildArguments += "/p:BuildNative=false" }
241-
if ($NoBuildNodeJS) { $MSBuildArguments += "/p:BuildNodeJS=false" }
242-
if ($NoBuildJava) { $MSBuildArguments += "/p:BuildJava=false" }
243-
244227
$RunBuild = if ($NoBuild) { $false } else { $true }
245228

246229
# Run restore by default unless -NoRestore is set.
@@ -276,6 +259,30 @@ if ($DotNetRuntimeSourceFeed -or $DotNetRuntimeSourceFeedKey) {
276259
$ToolsetBuildArguments += $runtimeFeedKeyArg
277260
}
278261

262+
# Split build categories between dotnet msbuild and desktop msbuild. Use desktop msbuild as little as possible.
263+
[string[]]$dotnetBuildArguments = $MSBuildArguments
264+
if ($All) { $dotnetBuildArguments += '/p:BuildAllProjects=true'; $BuildNative = $true }
265+
266+
if ($NoBuildInstallers) { $MSBuildArguments += "/p:BuildInstallers=false"; $BuildInstallers = $false }
267+
if ($BuildInstallers) { $MSBuildArguments += "/p:BuildInstallers=true" }
268+
if ($NoBuildNative) { $MSBuildArguments += "/p:BuildNative=false"; $BuildNative = $false }
269+
if ($BuildNative) { $MSBuildArguments += "/p:BuildNative=true"}
270+
271+
if ($NoBuildJava) { $dotnetBuildArguments += "/p:BuildJava=false"; $BuildJava = $false }
272+
if ($BuildJava) { $dotnetBuildArguments += "/p:BuildJava=true" }
273+
if ($NoBuildManaged) { $dotnetBuildArguments += "/p:BuildManaged=false"; $BuildManaged = $false }
274+
if ($BuildManaged) { $dotnetBuildArguments += "/p:BuildManaged=true" }
275+
if ($NoBuildNodeJS) { $dotnetBuildArguments += "/p:BuildNodeJS=false"; $BuildNodeJS = $false }
276+
if ($BuildNodeJS) { $dotnetBuildArguments += "/p:BuildNodeJS=true" }
277+
278+
# Don't bother with two builds if just one will build everything. Ignore super-weird cases like
279+
# "-Projects ... -NoBuildJava -NoBuildManaged -NoBuildNodeJS".
280+
$ForceCoreMsbuild = $ForceCoreMsbuild -or -not ($BuildInstallers -or $BuildNative) -or `
281+
$Architecture.StartsWith("arm", [System.StringComparison]::OrdinalIgnoreCase)
282+
$performDotnetBuild = $ForceCoreMsbuild -or $BuildJava -or $BuildManaged -or $BuildNodeJS -or `
283+
($All -and -not ($NoBuildJava -and $NoBuildManaged -and $NoBuildNodeJS)) -or `
284+
($Projects -and -not ($BuildInstallers -or $BuildNative))
285+
279286
$foundJdk = $false
280287
$javac = Get-Command javac -ErrorAction Ignore -CommandType Application
281288
$localJdkPath = "$PSScriptRoot\.tools\jdk\win-x64\"
@@ -343,9 +350,8 @@ $env:MSBUILDDISABLENODEREUSE=1
343350
# Fixing this is tracked by https://github.com/dotnet/aspnetcore-internal/issues/601
344351
$warnAsError = $false
345352

346-
if ($ForceCoreMsbuild) {
347-
$msbuildEngine = 'dotnet'
348-
}
353+
# Use `dotnet msbuild` by default
354+
$msbuildEngine = 'dotnet'
349355

350356
# Ensure passing neither -bl nor -nobl on CI avoids errors in tools.ps1. This is needed because both parameters are
351357
# $false by default i.e. they always exist. (We currently avoid binary logs but that is made visible in the YAML.)
@@ -367,7 +373,16 @@ Remove-Item variable:global:_MSBuildExe -ea Ignore
367373
if ($BinaryLog) {
368374
$bl = GetMSBuildBinaryLogCommandLineArgument($MSBuildArguments)
369375
if (-not $bl) {
370-
$MSBuildArguments += "/bl:" + (Join-Path $LogDir "Build.binlog")
376+
$dotnetBuildArguments += "/bl:" + (Join-Path $LogDir "Build.binlog")
377+
$MSBuildArguments += "/bl:" + (Join-Path $LogDir "Build.native.binlog")
378+
$ToolsetBuildArguments += "/bl:" + (Join-Path $LogDir "Build.repotasks.binlog")
379+
} else {
380+
# Use a different binary log path when running desktop msbuild if doing both builds.
381+
if (-not $ForceCoreMsbuild -and $performDotnetBuild) {
382+
$MSBuildArguments += [System.IO.Path]::ChangeExtension($bl, "native.binlog")
383+
}
384+
385+
$ToolsetBuildArguments += [System.IO.Path]::ChangeExtension($bl, "repotasks.binlog")
371386
}
372387
}
373388

@@ -391,6 +406,8 @@ try {
391406
}
392407

393408
if (-not $NoBuildRepoTasks) {
409+
Write-Host
410+
394411
MSBuild $toolsetBuildProj `
395412
/p:RepoRoot=$RepoRoot `
396413
/p:Projects=$EngRoot\tools\RepoTasks\RepoTasks.csproj `
@@ -401,9 +418,21 @@ try {
401418
@ToolsetBuildArguments
402419
}
403420

404-
MSBuild $toolsetBuildProj `
405-
/p:RepoRoot=$RepoRoot `
406-
@MSBuildArguments
421+
if (-not $ForceCoreMsbuild) {
422+
Write-Host
423+
Remove-Item variable:global:_BuildTool
424+
$msbuildEngine = 'vs'
425+
426+
MSBuild $toolsetBuildProj /p:RepoRoot=$RepoRoot @MSBuildArguments
427+
}
428+
429+
if ($performDotnetBuild) {
430+
Write-Host
431+
Remove-Item variable:global:_BuildTool
432+
$msbuildEngine = 'dotnet'
433+
434+
MSBuild $toolsetBuildProj /p:RepoRoot=$RepoRoot @dotnetBuildArguments
435+
}
407436
}
408437
catch {
409438
Write-Host $_.ScriptStackTrace

0 commit comments

Comments
 (0)