Skip to content

Commit ee80cd5

Browse files
authored
Build native assets by default (#22611)
* Build native assets by default - #22556 - make `-BuildNative` primarily useful when you want _only_ native assets - can also build `-Projects` with desktop `msbuild` using `-BuildNative` - remove `-ForceCoreMsbuild` option nit: extra `Remove-Item`s caused `MSBuild` function to do redundant work * !fixup! Get `/bl` options working again nit: Place SiteExtensions .binlogs correctly wherever script is run from * !fixup! Remove *.vcxproj from Servers build - native projects are built implicitly * !fixup! Remove `-buildNative` from IIS build script
1 parent eb33b96 commit ee80cd5

File tree

5 files changed

+46
-30
lines changed

5 files changed

+46
-30
lines changed

build.ps1

Lines changed: 39 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ You can also use -NoBuildManaged to suppress this project type.
5454
5555
.PARAMETER BuildNative
5656
Build native projects (C++).
57-
You can also use -NoBuildNative to suppress this project type.
57+
This is the default for x64 and x86 builds but useful when you want to build _only_ native projects.
58+
You can use -NoBuildNative to suppress this project type.
5859
5960
.PARAMETER BuildNodeJS
6061
Build NodeJS projects (TypeScript, JS).
@@ -89,8 +90,21 @@ Key for feed that can be used when downloading .NET runtimes
8990
.EXAMPLE
9091
Building both native and managed projects.
9192
93+
build.ps1
94+
95+
or
96+
97+
build.ps1 -BuildManaged
98+
99+
or
100+
92101
build.ps1 -BuildManaged -BuildNative
93102
103+
.EXAMPLE
104+
Build only native projects.
105+
106+
build.ps1 -BuildNative
107+
94108
.EXAMPLE
95109
Building a subfolder of code.
96110
@@ -146,10 +160,6 @@ param(
146160

147161
[switch]$NoBuildRepoTasks,
148162

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.
151-
[switch]$ForceCoreMsbuild,
152-
153163
# Diagnostics
154164
[Alias('bl')]
155165
[switch]$BinaryLog,
@@ -191,15 +201,12 @@ if ($Projects) {
191201
{
192202
$Projects = Join-Path (Get-Location) $Projects
193203
}
194-
$MSBuildArguments += "/p:ProjectToBuild=$Projects"
195204
}
196205
# When adding new sub-group build flags, add them to this check.
197206
elseif (-not ($All -or $BuildNative -or $BuildManaged -or $BuildNodeJS -or $BuildInstallers -or $BuildJava)) {
198-
Write-Warning "No default group of projects was specified, so building the 'managed' and its dependent subsets of projects. Run ``build.cmd -help`` for more details."
199-
200-
# This goal of this is to pick a sensible default for `build.cmd` with zero arguments.
201-
# Now that we support subfolder invokations of build.cmd, we will be pushing to have build.cmd build everything (-all) by default
207+
Write-Warning "No default group of projects was specified, so building the managed and native projects and their dependencies. Run ``build.cmd -help`` for more details."
202208

209+
# The goal of this is to pick a sensible default for `build.cmd` with zero arguments.
203210
$BuildManaged = $true
204211
}
205212

@@ -261,10 +268,21 @@ if ($DotNetRuntimeSourceFeed -or $DotNetRuntimeSourceFeedKey) {
261268

262269
# Split build categories between dotnet msbuild and desktop msbuild. Use desktop msbuild as little as possible.
263270
[string[]]$dotnetBuildArguments = $MSBuildArguments
264-
if ($All) { $dotnetBuildArguments += '/p:BuildAllProjects=true'; $BuildNative = $true }
271+
if ($All) { $dotnetBuildArguments += '/p:BuildAllProjects=true' }
272+
if ($Projects) {
273+
if ($BuildNative) {
274+
$MSBuildArguments += "/p:ProjectToBuild=$Projects"
275+
} else {
276+
$dotnetBuildArguments += "/p:ProjectToBuild=$Projects"
277+
}
278+
}
265279

266280
if ($NoBuildInstallers) { $MSBuildArguments += "/p:BuildInstallers=false"; $BuildInstallers = $false }
267281
if ($BuildInstallers) { $MSBuildArguments += "/p:BuildInstallers=true" }
282+
283+
# Build native projects by default unless -NoBuildNative was specified.
284+
$specifiedBuildNative = $BuildNative
285+
$BuildNative = $true
268286
if ($NoBuildNative) { $MSBuildArguments += "/p:BuildNative=false"; $BuildNative = $false }
269287
if ($BuildNative) { $MSBuildArguments += "/p:BuildNative=true"}
270288

@@ -276,12 +294,13 @@ if ($NoBuildNodeJS) { $dotnetBuildArguments += "/p:BuildNodeJS=false"; $BuildNod
276294
if ($BuildNodeJS) { $dotnetBuildArguments += "/p:BuildNodeJS=true" }
277295

278296
# 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 `
297+
# "-Projects ... -NoBuildJava -NoBuildManaged -NoBuildNodeJS". An empty `./build.ps1` command will build both
298+
# managed and native projects.
299+
$performDesktopBuild = ($BuildInstallers -or $BuildNative) -and `
300+
-not $Architecture.StartsWith("arm", [System.StringComparison]::OrdinalIgnoreCase)
301+
$performDotnetBuild = $BuildJava -or $BuildManaged -or $BuildNodeJS -or `
283302
($All -and -not ($NoBuildJava -and $NoBuildManaged -and $NoBuildNodeJS)) -or `
284-
($Projects -and -not ($BuildInstallers -or $BuildNative))
303+
($Projects -and -not ($BuildInstallers -or $specifiedBuildNative))
285304

286305
$foundJdk = $false
287306
$javac = Get-Command javac -ErrorAction Ignore -CommandType Application
@@ -378,11 +397,11 @@ if ($BinaryLog) {
378397
$ToolsetBuildArguments += "/bl:" + (Join-Path $LogDir "Build.repotasks.binlog")
379398
} else {
380399
# 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")
400+
if ($performDesktopBuild -and $performDotnetBuild) {
401+
$MSBuildArguments += "/bl:" + [System.IO.Path]::ChangeExtension($bl, "native.binlog")
383402
}
384403

385-
$ToolsetBuildArguments += [System.IO.Path]::ChangeExtension($bl, "repotasks.binlog")
404+
$ToolsetBuildArguments += "/bl:" + [System.IO.Path]::ChangeExtension($bl, "repotasks.binlog")
386405
}
387406
} elseif ($CI) {
388407
# Ensure the artifacts/log directory isn't empty to avoid warnings.
@@ -421,7 +440,7 @@ try {
421440
@ToolsetBuildArguments
422441
}
423442

424-
if (-not $ForceCoreMsbuild) {
443+
if ($performDesktopBuild) {
425444
Write-Host
426445
Remove-Item variable:global:_BuildTool -ErrorAction Ignore
427446
$msbuildEngine = 'vs'

eng/scripts/GenerateReferenceAssemblies.ps1

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@ try {
1010
& "$repoRoot\build.ps1" -ci:$ci -nobl -noBuildRepoTasks -noRestore -buildNative -configuration Debug
1111

1212
Remove-Item variable:global:_BuildTool -ErrorAction Ignore
13-
Remove-Item variable:global:_DotNetInstallDir -ErrorAction Ignore
14-
Remove-Item variable:global:_ToolsetBuildProj -ErrorAction Ignore
15-
Remove-Item variable:global:_MSBuildExe -ErrorAction Ignore
1613

1714
$excludeCIBinarylog = $true
1815
$msbuildEngine = 'dotnet'

src/Servers/IIS/build.cmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
@ECHO OFF
22
SET RepoRoot=%~dp0..\..\..
3-
%RepoRoot%\build.cmd -BuildNative -projects %~dp0**\*.csproj %*
3+
%RepoRoot%\build.cmd -projects %~dp0**\*.csproj %*

src/Servers/build.cmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
@ECHO OFF
22
SET RepoRoot=%~dp0..\..
3-
%RepoRoot%\build.cmd -projects %~dp0**\*.*proj %*
3+
%RepoRoot%\build.cmd -projects %~dp0**\*.csproj %*

src/SiteExtensions/build.cmd

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ SET RepoRoot=%~dp0..\..
33

44
ECHO Building x64 Microsoft.AspNetCore.Runtime.SiteExtension
55
CALL "%RepoRoot%\build.cmd" -arch x64 -projects "%~dp0Runtime\Microsoft.AspNetCore.Runtime.SiteExtension.pkgproj" ^
6-
/bl:artifacts/log/SiteExtensions-Runtime-x86.binlog %*
6+
"/bl:%RepoRoot%/artifacts/log/SiteExtensions-Runtime-x86.binlog" %*
77
IF %ERRORLEVEL% NEQ 0 (
88
EXIT /b %ErrorLevel%
99
)
1010

1111
ECHO Building x86 Microsoft.AspNetCore.Runtime.SiteExtension
1212
CALL "%RepoRoot%\build.cmd" -arch x86 -projects "%~dp0Runtime\Microsoft.AspNetCore.Runtime.SiteExtension.pkgproj" ^
13-
/bl:artifacts/log/SiteExtensions-Runtime-x86.binlog %*
13+
"/bl:%RepoRoot%/artifacts/log/SiteExtensions-Runtime-x86.binlog" %*
1414
IF %ERRORLEVEL% NEQ 0 (
1515
EXIT /b %ErrorLevel%
1616
)
@@ -19,22 +19,22 @@ ECHO Building x64 LoggingBranch
1919
REM /p:DisableTransitiveFrameworkReferences=true is needed to prevent SDK from picking up transitive references to
2020
REM Microsoft.AspNetCore.App as framework references https://github.com/dotnet/sdk/pull/3221
2121
CALL "%RepoRoot%\build.cmd" -arch x64 -projects "%~dp0LoggingBranch\LB.csproj" ^
22-
/p:DisableTransitiveFrameworkReferences=true /bl:artifacts/log/SiteExtensions-LoggingBranch-x64.binlog %*
22+
/p:DisableTransitiveFrameworkReferences=true "/bl:%RepoRoot%/artifacts/log/SiteExtensions-LoggingBranch-x64.binlog" %*
2323
IF %ERRORLEVEL% NEQ 0 (
2424
EXIT /b %ErrorLevel%
2525
)
2626

2727
ECHO Building x86 LoggingBranch
2828
CALL "%RepoRoot%\build.cmd" -arch x86 -projects "%~dp0LoggingBranch\LB.csproj" ^
29-
/p:DisableTransitiveFrameworkReferences=true /bl:artifacts/log/SiteExtensions-LoggingBranch-x86.binlog %*
29+
/p:DisableTransitiveFrameworkReferences=true "/bl:%RepoRoot%/artifacts/log/SiteExtensions-LoggingBranch-x86.binlog" %*
3030
IF %ERRORLEVEL% NEQ 0 (
3131
EXIT /b %ErrorLevel%
3232
)
3333

3434
ECHO Building Microsoft.AspNetCore.AzureAppServices.SiteExtension
3535
CALL "%RepoRoot%\build.cmd" -projects ^
3636
"%~dp0LoggingAggregate\src\Microsoft.AspNetCore.AzureAppServices.SiteExtension\Microsoft.AspNetCore.AzureAppServices.SiteExtension.csproj" ^
37-
/bl:artifacts/log/SiteExtensions-LoggingAggregate.binlog %*
37+
"/bl:%RepoRoot%/artifacts/log/SiteExtensions-LoggingAggregate.binlog" %*
3838
IF %ERRORLEVEL% NEQ 0 (
3939
EXIT /b %ErrorLevel%
4040
)

0 commit comments

Comments
 (0)