-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Static Web Assets] Reworks the protocol for getting referenced assets and brings back backwards compatibility #19482
Conversation
I couldn't figure out the best area label to add to this PR. If you have write-permissions please help me learn by adding exactly one area label. |
2bc77f4
to
bad4dad
Compare
This is ready for review, the main commits to review are: d9244e4 There is a commit that adds tests for all scenarios we care about. I've put all the generated baselines into their own commit since I've also been doing fixes. The additional tests are also on their own commit, and you can check the associated baseline if you want to see if we are generating the right results. |
/azp run |
Azure Pipelines successfully started running 1 pipeline(s). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes look good. Some questions about test coverage
src/Tests/Microsoft.NET.Sdk.BlazorWebAssembly.Tests/BlazorWasmStaticWebAssetsIntegrationTest.cs
Outdated
Show resolved
Hide resolved
src/Tests/Microsoft.NET.Sdk.Razor.Tests/StaticWebAssetsIntegrationTest.cs
Show resolved
Hide resolved
2c8f963
to
ddaddf4
Compare
… there are assets present
190fc7f
to
1dd270d
Compare
This reverts commit 8185b2e.
…information # By dotnet-maestro[bot] (4) and others # Via GitHub * origin/main: (58 commits) Localized file check-in by OneLocBuild Task (dotnet#57384) [debugger][wasm] Support DebuggerProxyAttribute (dotnet#56872) Account for type mismatch of `FIELD_LIST` members in LSRA (dotnet#57450) Qualify `sorted_table` allocation with `nothrow` (dotnet#57467) Rename transport packages to follow convention (dotnet#57504) Generate proper DWARF reg num for ARM32 (dotnet#57443) Enable System.Linq.Queryable and disable dotnet#50712 (dotnet#57464) Mark individual tests for 51211 (dotnet#57463) Fix Length for ReadOnlySequence created out of sliced Memory owned by MemoryManager (dotnet#57479) Add JsonConverter.Write/ReadAsPropertyName APIs (dotnet#57302) Remove workaround for dotnet/sdk#19482 (dotnet#57453) Do not drain HttpContentReadStream if the connection is disposed (dotnet#57287) [mono] Fix a few corner case overflow operations (dotnet#57407) make use of ports in SPN optional (dotnet#57159) Fixed H/3 stress server after the last Kestrel change (dotnet#57356) disable a failing stress test. (dotnet#57473) Eliminate temporary byte array allocations in the static constructor of `IPAddress`. (dotnet#57397) Update dependencies from https://github.com/dotnet/emsdk build 20210815.1 (dotnet#57447) [main] Update dependencies from mono/linker (dotnet#57344) Improve serializer performance (dotnet#57327) ... # Conflicts: # src/mono/wasm/debugger/BrowserDebugProxy/MemberReferenceResolver.cs # src/mono/wasm/debugger/BrowserDebugProxy/MonoProxy.cs # src/mono/wasm/debugger/BrowserDebugProxy/MonoSDBHelper.cs
Static web assets cleanups
Goals
into them to get the list of static web asset items.
Other work/cleanups
standard
targets where features can attach themselves to generatetheir assets.
Details
In the initial implementation of static web assets V2, we generated a manifest
and asked every referenced project to give us their manifest. This worked but it
incurred in the additional cost of having to read each referenced project manifest
every time we had to compute the manifest for a given project.
In addition to that, it was costly/impossible to support backwards compatibility with previous versions of static web assets, since they use different targets and work in a very different way.
Finally, the old implementation relied on the old project knowing all the details about referenced projects to compute the list of assets, which added complexity to the implementation.
The changes in this PR bring the implementation closer to the original implementation and make it more performant, backwards compatible and simpler.
Static web assets with referenced projects works as follows:
based on the configuration they gave us.
based on the configuration they gave us.
The initial step is to call GetStaticWebAssetsProjectConfiguration on all projects. This step defines how the remaining steps work by returning an item group that includes the version, the source, the targets and properties to call to get the static web assets for the project during build and publish.
Static web assets V2 defines a standard target
GetCurrentProjectBuildStaticWebAssetItems
that it calls when no other target has been defined. Projects can change this by settingStaticWebAssetsGetBuildAssetsTargets
A similar thing happens for publish assets, we will call
ComputeReferencedStaticWebAssetsPublishManifest;GetCurrentProjectPublishStaticWebAssetItems
by default to make sure that the publish asset manifest is generated and retrieve the assets afterwards. Each project can change this by settingStaticWebAssetsGetPublishAssetsTargets
.In addition to that, there are properties that projects can configure to define how we should retrieve their assets:
StaticWebAssetsAdditionalBuildProperties
StaticWebAssetsAdditionalBuildPropertiesToRemove
StaticWebAssetsAdditionalPublishProperties
StaticWebAssetsAdditionalPublishPropertiesToRemove
These properties are mostly for our
internal
use and enable us to adapt how static web assets work in different environments, like blazor webassembly or blazor desktop, without burdening those projects with unnecessary details.This functionality is used also by older projects to bring forward compatibility with the new version of static web assets.
The 6.0 SDK forks static web assets and blazor based on whether the user is targeting 6.0 or earlier, we do this to avoid breaking backwards compatibility with previous versions given the amount of changes we've made to how static web assets work.
If a project targets net6.0 or higher it will load static web assets v2, otherwise, it will load v1, which live in different targets files.
We've updated the V1 SDK file to include targets to bring forward compatibility with static web assets V2.
V1 static web assets define a GetStaticWebAssetsProjectConfiguration target that returns the configuration to use for retrieving the assets. The only important element they return is
GetCurrentProjectStaticWebAssetsV2
for retrieving the static web asssets during build.V1 static web assets projects don't define different assets during publish, so they don't return publish specific static web assets targets as part of their configuration.
Static web assets v1, scoped css v1, and blazor webassembly 5.0, attach to
GetCurrentProjectStaticWebAssetsV2
and update the assets properties to adapt them to static web assets v2.Finally, by calling the referenced projects for their assets, we simplify how the assets are computed when the assets are being referenced by another project.
Other work details
Make publish respect PreserveNewest
This was missing and its obvious, we were just copying the assets to the publish output folder, we now split them by PreserveNewest or Always and do the appropriate thing.
Define standard targets for generating static web assets
Assets can do work at two points:
This makes it easier to adapt when the pipeline targets run in different environments (Webassembly, Maui) without them requiring intimate knowledge of every static web asset feature.