Skip to content

Commit 43350b5

Browse files
author
John Luo
authored
Revert "Revert "Improve components infrastructure (#12145)" (#12679)" (#12744)
* Revert "Revert "Improve components infrastructure (#12145)" (#12679)" This reverts commit e2d57e2. The improvement to components infrastructure is now reinstated with the following changes: * Check in release JS artifacts and use them as a fallback when it's not possible to build npmproj. * Dont' build nodejs in source build.
1 parent 397f924 commit 43350b5

16 files changed

+161
-55
lines changed

.azure/pipelines/ci.yml

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ variables:
2929
- ${{ if or(eq(variables['System.TeamProject'], 'public'), in(variables['Build.Reason'], 'PullRequest')) }}:
3030
- name: _BuildArgs
3131
value: ''
32+
3233
jobs:
34+
# Code check
3335
- template: jobs/default-build.yml
3436
parameters:
3537
jobName: Code_check
@@ -38,6 +40,10 @@ jobs:
3840
steps:
3941
- powershell: ./eng/scripts/CodeCheck.ps1 -ci
4042
displayName: Run eng/scripts/CodeCheck.ps1
43+
artifacts:
44+
- name: Code_Check_Logs
45+
path: artifacts/log/
46+
publishOnError: true
4147

4248
# Build Windows (x64/x86)
4349
- template: jobs/default-build.yml
@@ -171,6 +177,7 @@ jobs:
171177
-bl:artifacts/log/build.macos.binlog
172178
$(_BuildArgs)
173179
installNodeJs: false
180+
installJdk: false
174181
artifacts:
175182
- name: MacOS_x64_Packages
176183
path: artifacts/packages/
@@ -191,7 +198,6 @@ jobs:
191198
jobName: Linux_x64_build
192199
jobDisplayName: "Build: Linux x64"
193200
agentOs: Linux
194-
installNodeJs: false
195201
steps:
196202
- script: ./build.sh
197203
--ci
@@ -211,6 +217,7 @@ jobs:
211217
--arch x64 \
212218
--build-installers \
213219
--no-build-deps \
220+
--no-build-nodejs \
214221
-p:OnlyPackPlatformSpecificPackages=true \
215222
-p:BuildRuntimeArchive=false \
216223
-p:LinuxInstallerType=deb \
@@ -224,12 +231,15 @@ jobs:
224231
--arch x64 \
225232
--build-installers \
226233
--no-build-deps \
234+
--no-build-nodejs \
227235
-p:OnlyPackPlatformSpecificPackages=true \
228236
-p:BuildRuntimeArchive=false \
229237
-p:LinuxInstallerType=rpm \
230238
-bl:artifacts/log/build.rpm.binlog \
231239
$(_BuildArgs)
232240
displayName: Build RPM installers
241+
installNodeJs: false
242+
installJdk: false
233243
artifacts:
234244
- name: Linux_x64_Packages
235245
path: artifacts/packages/
@@ -260,6 +270,7 @@ jobs:
260270
-bl:artifacts/log/build.linux-arm.binlog
261271
$(_BuildArgs)
262272
installNodeJs: false
273+
installJdk: false
263274
artifacts:
264275
- name: Linux_arm_Packages
265276
path: artifacts/packages/
@@ -290,6 +301,7 @@ jobs:
290301
-bl:artifacts/log/build.arm64.binlog
291302
$(_BuildArgs)
292303
installNodeJs: false
304+
installJdk: false
293305
artifacts:
294306
- name: Linux_arm64_Packages
295307
path: artifacts/packages/
@@ -323,6 +335,7 @@ jobs:
323335
-bl:artifacts/log/build.musl.binlog
324336
$(_BuildArgs)
325337
installNodeJs: false
338+
installJdk: false
326339
artifacts:
327340
- name: Linux_musl_x64_Packages
328341
path: artifacts/packages/
@@ -337,7 +350,7 @@ jobs:
337350
parameters:
338351
inputName: Linux_musl_x64
339352

340-
# Build Linux Musl arm64
353+
# Build Linux Musl ARM64
341354
- template: jobs/default-build.yml
342355
parameters:
343356
jobName: Linux_musl_arm64_build
@@ -356,6 +369,7 @@ jobs:
356369
-bl:artifacts/log/build.musl.binlog
357370
$(_BuildArgs)
358371
installNodeJs: false
372+
installJdk: false
359373
artifacts:
360374
- name: Linux_musl_arm64_Packages
361375
path: artifacts/packages/
@@ -499,7 +513,7 @@ jobs:
499513
version: 3.0.x
500514
installationPath: $(DotNetCoreSdkDir)
501515
includePreviewVersions: true
502-
- script: ./eng/scripts/ci-source-build.sh --ci --configuration Release /p:BuildManaged=true
516+
- script: ./eng/scripts/ci-source-build.sh --ci --configuration Release /p:BuildManaged=true /p:BuildNodeJs=false
503517
displayName: Run ci-source-build.sh
504518
- task: PublishBuildArtifacts@1
505519
displayName: Upload logs

build.ps1

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,14 +183,33 @@ elseif ($Projects) {
183183
}
184184
# When adding new sub-group build flags, add them to this check.
185185
elseif((-not $BuildNative) -and (-not $BuildManaged) -and (-not $BuildNodeJS) -and (-not $BuildInstallers) -and (-not $BuildJava)) {
186-
Write-Warning "No default group of projects was specified, so building the 'managed' subsets of projects. Run ``build.cmd -help`` for more details."
186+
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."
187187

188188
# This goal of this is to pick a sensible default for `build.cmd` with zero arguments.
189189
# Now that we support subfolder invokations of build.cmd, we will be pushing to have build.cmd build everything (-all) by default
190190

191191
$BuildManaged = $true
192192
}
193193

194+
if ($BuildManaged -or ($All -and (-not $NoBuildManaged))) {
195+
if ((-not $BuildNodeJS) -and (-not $NoBuildNodeJS)) {
196+
$node = Get-Command node -ErrorAction Ignore -CommandType Application
197+
198+
if ($node) {
199+
$nodeHome = Split-Path -Parent (Split-Path -Parent $node.Path)
200+
Write-Host -f Magenta "Building of C# project is enabled and has dependencies on NodeJS projects. Building of NodeJS projects is enabled since node is detected in $nodeHome."
201+
}
202+
else {
203+
Write-Host -f Magenta "Building of NodeJS projects is disabled since node is not detected on Path and no BuildNodeJs or NoBuildNodeJs setting is set explicitly."
204+
$NoBuildNodeJS = $true
205+
}
206+
}
207+
208+
if ($NoBuildNodeJS){
209+
Write-Warning "Some managed projects depend on NodeJS projects. Building NodeJS is disabled so the managed projects will fallback to using the output from previous builds. The output may not be correct or up to date."
210+
}
211+
}
212+
194213
if ($BuildInstallers) { $MSBuildArguments += "/p:BuildInstallers=true" }
195214
if ($BuildManaged) { $MSBuildArguments += "/p:BuildManaged=true" }
196215
if ($BuildNative) { $MSBuildArguments += "/p:BuildNative=true" }

build.sh

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,14 +213,29 @@ elif [ ! -z "$build_projects" ]; then
213213
elif [ -z "$build_managed" ] && [ -z "$build_nodejs" ] && [ -z "$build_java" ] && [ -z "$build_native" ] && [ -z "$build_installers" ]; then
214214
# This goal of this is to pick a sensible default for `build.sh` with zero arguments.
215215
# We believe the most common thing our contributors will work on is C#, so if no other build group was picked, build the C# projects.
216-
__warn "No default group of projects was specified, so building the 'managed' subset of projects. Run ``build.sh --help`` for more details."
216+
__warn "No default group of projects was specified, so building the 'managed' and its dependent subset of projects. Run ``build.sh --help`` for more details."
217217
build_managed=true
218218
fi
219219

220220
if [ "$build_deps" = false ]; then
221221
msbuild_args[${#msbuild_args[*]}]="-p:BuildProjectReferences=false"
222222
fi
223223

224+
if [ "$build_managed" = true ] || (["$build_all" = true ] && [ "$build_managed" != false ]); then
225+
if [ -z "$build_nodejs" ]; then
226+
if [ -x "$(command -v node)" ]; then
227+
__warn "Building of C# project is enabled and has dependencies on NodeJS projects. Building of NodeJS projects is enabled since node is detected on PATH."
228+
else
229+
__warn "Building of NodeJS projects is disabled since node is not detected on Path and no BuildNodeJs or NoBuildNodeJs setting is set explicitly."
230+
build_nodejs=false
231+
fi
232+
fi
233+
234+
if [ "$build_nodejs" = false ]; then
235+
__warn "Some managed projects depend on NodeJS projects. Building NodeJS is disabled so the managed projects will fallback to using the output from previous builds. The output may not be correct or up to date."
236+
fi
237+
fi
238+
224239
# Only set these MSBuild properties if they were explicitly set by build parameters.
225240
[ ! -z "$build_java" ] && msbuild_args[${#msbuild_args[*]}]="-p:BuildJava=$build_java"
226241
[ ! -z "$build_native" ] && msbuild_args[${#msbuild_args[*]}]="-p:BuildNative=$build_native"

docs/BuildFromSource.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,14 +97,14 @@ The cause of this problem is that the solution you are using does not include th
9797
```
9898
9999
### Common error: Unable to locate the .NET Core SDK
100-
100+
101101
Executing `.\restore.cmd` or `.\build.cmd` may produce these errors:
102102
103103
> error : Unable to locate the .NET Core SDK. Check that it is installed and that the version specified in global.json (if any) matches the installed version.
104104
> error MSB4236: The SDK 'Microsoft.NET.Sdk' specified could not be found.
105105
106106
In most cases, this is because the option _Use previews of the .NET Core SDK_ in VS2019 is not checked. Start Visual Studio, go to _Tools > Options_ and check _Use previews of the .NET Core SDK_ under _Environment > Preview Features_.
107-
107+
108108
## Building with Visual Studio Code
109109
110110
Using Visual Studio Code with this repo requires setting environment variables on command line first.
@@ -138,6 +138,8 @@ On macOS/Linux:
138138
./build.sh
139139
```
140140

141+
By default, all of the C# projects are built. Some C# projects requires NodeJS to be installed to compile JavaScript assets which are then checked in as source. If NodeJS is detected on the path, the NodeJS projects will be compiled as part of building C# projects. If NodeJS is not detected on the path, the JavaScript assets checked in previously will be used instead. To disable building NodeJS projects, specify /p:BuildNodeJs=false on the command line.
142+
141143
### Using `dotnet` on command line in this repo
142144

143145
Because we are using pre-release versions of .NET Core, you have to set a handful of environment variables

eng/Build.props

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,16 @@
44
</PropertyGroup>
55

66
<PropertyGroup Condition=" '$(BuildAllProjects)' == 'true' ">
7-
<BuildNative>true</BuildNative>
8-
<BuildManaged>true</BuildManaged>
9-
<BuildNodeJS>true</BuildNodeJS>
10-
<BuildJava>true</BuildJava>
7+
<BuildNative Condition="'$(BuildNative)' == ''">true</BuildNative>
8+
<BuildManaged Condition="'$(BuildManaged)' == ''">true</BuildManaged>
9+
<BuildNodeJS Condition="'$(BuildNodeJS)' == ''">true</BuildNodeJS>
10+
<BuildJava Condition="'$(BuildJava)' == ''">true</BuildJava>
1111
</PropertyGroup>
1212

1313
<!-- These projects are always excluded, even when -projects is specified on command line. -->
1414
<ItemGroup>
15+
<!-- Explicitly excluded projects -->
16+
<ProjectToExclude Include="$(ProjectToExclude)" />
1517

1618
<!-- These projects use 'legacy' csproj, which is not supported by dotnet-msbuild. -->
1719
<ProjectToExclude Include="
@@ -31,6 +33,7 @@
3133
$(RepoRoot)src\submodules\**\*.*proj;
3234
$(RepoRoot)src\Installers\**\*.*proj;
3335
$(RepoRoot)src\SignalR\clients\ts\**\node_modules\**\*.*proj;
36+
$(RepoRoot)src\Components\Web.JS\node_modules\**\*.*proj;
3437
$(RepoRoot)src\Components\Blazor\Templates\src\content\**\*.*proj;
3538
$(RepoRoot)src\ProjectTemplates\Web.ProjectTemplates\content\**\*.csproj;
3639
$(RepoRoot)src\ProjectTemplates\Web.ProjectTemplates\content\**\*.fsproj;
@@ -43,7 +46,6 @@
4346
$(RepoRoot)src\Servers\Kestrel\perf\PlatformBenchmarks\**\*.csproj;
4447
$(RepoRoot)src\SignalR\perf\benchmarkapps\**\*.csproj;
4548
" />
46-
4749
</ItemGroup>
4850

4951
<Choose>
@@ -102,6 +104,7 @@
102104
<ProjectToExclude Condition=" '$(BuildNative)' != 'true'" Include="@(NativeProjects)" />
103105

104106
<NodeJsProjects Include="
107+
$(RepoRoot)src\Components\Web.JS\Microsoft.AspNetCore.Components.Web.JS.npmproj;
105108
$(RepoRoot)src\SignalR\**\*.npmproj;
106109
$(RepoRoot)src\Middleware\**\*.npmproj;
107110
"

eng/scripts/CodeCheck.ps1

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -166,11 +166,6 @@ try {
166166
& dotnet run -p "$repoRoot/eng/tools/BaselineGenerator/"
167167
}
168168

169-
Write-Host "Re-generating Web.JS files"
170-
Invoke-Block {
171-
& dotnet build "$repoRoot\src\Components\Web.JS\Microsoft.AspNetCore.Components.Web.JS.npmproj"
172-
}
173-
174169
Write-Host "Run git diff to check for pending changes"
175170

176171
# Redirect stderr to stdout because PowerShell does not consistently handle output to stderr

eng/targets/Npm.Common.targets

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,28 @@
1111
<IntermediateOutputPath>$([MSBuild]::NormalizeDirectory('$(BaseIntermediateOutputPath)'))$(Configuration)\</IntermediateOutputPath>
1212
<InstallArgs Condition="'$(RestoreLockedMode)' == 'true'">--frozen-lockfile</InstallArgs>
1313
<_BackupPackageJson>$(IntermediateOutputPath)$(MSBuildProjectName).package.json.bak</_BackupPackageJson>
14+
<BuildDependsOn>
15+
PrepareForBuild;
16+
ResolveProjectReferences;
17+
_Build;
18+
</BuildDependsOn>
19+
<NpmBuildArgs Condition="'$(NpmBuildArgs)' == ''">run build</NpmBuildArgs>
1420
</PropertyGroup>
1521

1622
<ItemGroup>
1723
<TSFiles Include="$(MSBuildProjectDirectory)\*\*.ts" />
1824
<TSFiles Include="$(MSBuildProjectDirectory)\package.json" />
25+
<TSFiles Include="$(MSBuildProjectDirectory)\*.npmproj" />
1926
</ItemGroup>
2027

2128
<Target Name="_CheckForInvalidConfiguration">
2229
<Error Text="Missing expected property: PackageId" Condition="'$(IsPackable)' != 'false' and '$(PackageId)' == ''" />
30+
31+
<Exec ContinueOnError="true" Command="node -v">
32+
<Output TaskParameter="ExitCode" PropertyName="ErrorCode"/>
33+
</Exec>
34+
35+
<Error Text="Building *.npmproj but NodeJS was not detected on path. Ensure NodeJS is on path or disable building NodeJS projects with /p:BuildNodeJs=false. Skipping NodeJS projects will also skip managed projects depending on them, including Components, Mvc and Analysers." Condition="'$(ErrorCode)' != '0'"/>
2336
</Target>
2437

2538
<Target Name="Restore">
@@ -36,13 +49,13 @@
3649
BuildInParallel="true" />
3750
</Target>
3851

39-
<Target Name="Build" DependsOnTargets="PrepareForBuild;ResolveProjectReferences;_Build" />
52+
<Target Name="Build" DependsOnTargets="$(BuildDependsOn)" />
4053

4154
<Target Name="_Build"
4255
Condition="'$(IsBuildable)' != 'false'"
4356
Inputs="@(TSFiles)"
4457
Outputs="$(BaseIntermediateOutputPath)\build-sentinel" >
45-
<Yarn Command="run build" StandardOutputImportance="High" StandardErrorImportance="High" />
58+
<Yarn Command="$(NpmBuildArgs)" StandardOutputImportance="High" StandardErrorImportance="High" />
4659
<WriteLinesToFile Overwrite="true" File="$(BaseIntermediateOutputPath)\build-sentinel" />
4760
</Target>
4861

src/Components/Blazor/testassets/MonoSanityClient/MonoSanityClient.csproj

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,4 @@
1111
<!-- loader.js is hard-coded to assume it can load .pdbs regardless of Debug/Release configuration -->
1212
<BlazorEnableDebugging>true</BlazorEnableDebugging>
1313
</PropertyGroup>
14-
15-
<ItemGroup>
16-
</ItemGroup>
1714
</Project>

src/Components/Directory.Build.targets

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,16 @@
55

66
<ItemGroup>
77
<None Include="$(MSBuildThisFileDirectory)THIRD-PARTY-NOTICES.txt" Pack="true" PackagePath="." />
8+
9+
<!-- Add a project dependency without reference output assemblies to enforce build order -->
10+
<!-- Applying workaround for https://github.com/microsoft/msbuild/issues/2661 and https://github.com/dotnet/sdk/issues/952 -->
11+
<ProjectReference
12+
Condition="'$(ReferenceBlazorBuildLocally)' == 'true' and '$(BuildNodeJS)' != 'false'"
13+
Include="$(RepoRoot)src\Components\Web.JS\Microsoft.AspNetCore.Components.Web.JS.npmproj"
14+
ReferenceOutputAssemblies="false"
15+
SkipGetTargetFrameworkProperties="true"
16+
UndefineProperties="TargetFramework"
17+
Private="false" />
818
</ItemGroup>
919

1020
<Import Project="Blazor\Build\src\ReferenceFromSource.props" Condition="'$(ReferenceBlazorBuildLocally)' == 'true'" />

src/Components/Server/src/Microsoft.AspNetCore.Components.Server.csproj

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,16 @@
2121
<Reference Include="Microsoft.Extensions.FileProviders.Embedded" />
2222
<Reference Include="Microsoft.Extensions.Logging" />
2323
<Reference Include="Microsoft.Extensions.ValueStopwatch.Sources" PrivateAssets="All" />
24+
25+
<!-- Add a project dependency without reference output assemblies to enforce build order -->
26+
<!-- Applying workaround for https://github.com/microsoft/msbuild/issues/2661 and https://github.com/dotnet/sdk/issues/952 -->
27+
<ProjectReference
28+
Include="..\..\Web.JS\Microsoft.AspNetCore.Components.Web.JS.npmproj"
29+
ReferenceOutputAssemblies="false"
30+
SkipGetTargetFrameworkProperties="true"
31+
UndefineProperties="TargetFramework"
32+
Private="false"
33+
Condition="'$(BuildNodeJS)' != 'false'" />
2434
</ItemGroup>
2535

2636
<PropertyGroup>
@@ -53,12 +63,7 @@
5363
</ItemGroup>
5464

5565
<PropertyGroup>
56-
<!--
57-
We check in the Release / Production build of blazor.*.js, but not the Debug builds. Consequently the former is always available to embed, the latter is only available
58-
if Web.JS was built locally. Use the Debug build when available and building in Debug configuration.
59-
-->
60-
<BlazorServerJSFile>..\..\Web.JS\dist\Release\blazor.server.js</BlazorServerJSFile>
61-
<BlazorServerJSFile Condition="'$(Configuration)' == 'Debug' AND Exists('..\..\Web.JS\dist\Debug\blazor.server.js')">..\..\Web.JS\dist\Debug\blazor.server.js</BlazorServerJSFile>
66+
<BlazorServerJSFile>..\..\Web.JS\dist\$(Configuration)\blazor.server.js</BlazorServerJSFile>
6267
</PropertyGroup>
6368

6469
<ItemGroup>

src/Components/Web.JS/Microsoft.AspNetCore.Components.Web.JS.npmproj

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,18 @@
77
</PropertyGroup>
88

99
<ItemGroup>
10-
<ProjectReference Include="..\..\SignalR\clients\ts\signalr\signalr.npmproj" />
11-
<ProjectReference Include="..\..\SignalR\clients\ts\signalr-protocol-msgpack\signalr-protocol-msgpack.npmproj" />
10+
<ProjectReference
11+
Include="..\..\SignalR\clients\ts\signalr\signalr.npmproj"
12+
ReferenceOutputAssemblies="false"
13+
SkipGetTargetFrameworkProperties="true"
14+
UndefineProperties="TargetFramework"
15+
Private="false" />
16+
<ProjectReference
17+
Include="..\..\SignalR\clients\ts\signalr-protocol-msgpack\signalr-protocol-msgpack.npmproj"
18+
ReferenceOutputAssemblies="false"
19+
SkipGetTargetFrameworkProperties="true"
20+
UndefineProperties="TargetFramework"
21+
Private="false" />
1222
</ItemGroup>
1323

1424
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), Directory.Build.targets))\Directory.Build.targets" />

0 commit comments

Comments
 (0)