Skip to content
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

Merged
merged 21 commits into from
Aug 7, 2021

Conversation

javiercn
Copy link
Member

@javiercn javiercn commented Aug 3, 2021

Static web assets cleanups

Goals

  • Bring back back-compat with earlier project types.
  • Avoid reading dependent projects static web asset manifests multiple times.
  • Allow dependent projects to specify how the referencing project should call
    into them to get the list of static web asset items.

Other work/cleanups

  • Make publish respect PreserveNewest.
  • Define standard targets where features can attach themselves to generate
    their 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:

  • Gather referenced projects configuration.
  • Call referenced projects during build to gather their static web assets
    based on the configuration they gave us.
  • Call referenced projects during publish to gather their static web assets
    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 setting StaticWebAssetsGetBuildAssetsTargets

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 setting StaticWebAssetsGetPublishAssetsTargets.

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:

  • If the feature needs to do work to compute the list of static web assets to add, it can do so during Resolve(Publish)StaticWebAssetInputs.
  • If the feature does not need to do work to compute the list of static web assets to add, it can declare the assets ahead of time during Resolve(Publish)StaticWebAssetInputs and attach to GenerateComputed(Build|Publish)StaticWebAssets to generate the assets when they are needed.

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.

@dotnet-issue-labeler
Copy link

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.

@javiercn javiercn added the Area-AspNetCore RazorSDK, BlazorWebAssemblySDK, dotnet-watch label Aug 3, 2021
@javiercn javiercn force-pushed the javiercn/static-web-assets-bring-back-compat branch 2 times, most recently from 2bc77f4 to bad4dad Compare August 4, 2021 13:52
@javiercn
Copy link
Member Author

javiercn commented Aug 4, 2021

This is ready for review, the main commits to review are: d9244e4
5bb7e6c

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.

@javiercn javiercn requested a review from pranavkm August 4, 2021 15:35
@javiercn
Copy link
Member Author

javiercn commented Aug 4, 2021

Only test failing is unrelated I think
image

@pranavkm
Copy link
Contributor

pranavkm commented Aug 4, 2021

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Copy link
Contributor

@pranavkm pranavkm left a 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

@javiercn javiercn force-pushed the javiercn/static-web-assets-bring-back-compat branch 2 times, most recently from 2c8f963 to ddaddf4 Compare August 7, 2021 13:03
@javiercn
Copy link
Member Author

javiercn commented Aug 7, 2021

dotnet/aspnetcore#35143

@javiercn javiercn force-pushed the javiercn/static-web-assets-bring-back-compat branch from 190fc7f to 1dd270d Compare August 7, 2021 17:27
@javiercn javiercn merged commit 60d659c into main Aug 7, 2021
SonicGD added a commit to sitkoru/Sitko.Blockly that referenced this pull request Aug 11, 2021
SonicGD added a commit to sitkoru/Sitko.Blockly that referenced this pull request Aug 12, 2021
lewing added a commit to lewing/runtime that referenced this pull request Aug 15, 2021
akoeplinger pushed a commit to dotnet/runtime that referenced this pull request Aug 16, 2021
thaystg added a commit to thaystg/runtime that referenced this pull request Aug 16, 2021
…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
@akoeplinger akoeplinger deleted the javiercn/static-web-assets-bring-back-compat branch February 14, 2024 14:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-AspNetCore RazorSDK, BlazorWebAssemblySDK, dotnet-watch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants