KEMBAR78
Replace UseStaticFiles() with MapStaticAssets() in Blazor Maui Web template by Copilot · Pull Request #31618 · dotnet/maui · GitHub
Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Sep 15, 2025

> [!NOTE]
> Are you waiting for the changes in this PR to be merged?
> It would be very helpful if you could test the resulting artifacts from this PR and let us know in a comment if this change resolves your issue. Thank you!

This PR updates the Blazor Maui Web template to use the modern ASP.NET Core MapStaticAssets() middleware instead of the legacy UseStaticFiles() middleware.

Changes Made

In src/Templates/src/templates/maui-blazor-solution/MauiApp.1.Web/Program.cs:

  • Removed: app.UseStaticFiles(); call
  • Added: app.MapStaticAssets(); call placed before MapRazorComponents()
  app.UseHttpsRedirection();

- app.UseStaticFiles();
  app.UseAntiforgery();

+ app.MapStaticAssets();
+
  #if (UseServer && UseWebAssembly)
  app.MapRazorComponents<App>()

Benefits

MapStaticAssets() is the recommended approach for serving static assets in modern ASP.NET Core applications as it:

  • Provides better performance through optimized asset serving
  • Enables improved caching strategies
  • Offers better integration with the routing pipeline
  • Follows current ASP.NET Core best practices

Testing

  • ✅ Template generation works correctly with dotnet new maui-blazor-web
  • ✅ Generated web projects build successfully
  • ✅ Static assets (CSS, JS) are served correctly at runtime
  • ✅ All HTTP requests to static files return expected responses

Fixes #31617.

Progress

  • Implement the core change from UseStaticFiles() to MapStaticAssets()
  • Revert unrelated changes to cgmanifest.json and templatestrings.json files
  • Verify the template still works correctly

💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

…mplate

Co-authored-by: javiercn <6995051+javiercn@users.noreply.github.com>
@Copilot Copilot AI changed the title [WIP] [Blazor][Maui] Use MapStaticAssets in the Blazor Maui Web template Replace UseStaticFiles() with MapStaticAssets() in Blazor Maui Web template Sep 15, 2025
@Copilot Copilot AI requested a review from javiercn September 15, 2025 14:12
Copilot finished work on behalf of javiercn September 15, 2025 14:12
Copy link
Member

@javiercn javiercn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot you have work

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot
Unrelated, undo this change.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Reverted the unrelated changes to cgmanifest.json. The file has been restored to its original state in commit 4536815.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot
Unrelated, undo this change.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Reverted the unrelated changes to this templatestrings.json file. All templatestrings.json files have been restored to their original state in commit 4536815.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot
Unrelated, undo this change.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Reverted the unrelated changes to this templatestrings.json file. All templatestrings.json files have been restored to their original state in commit 4536815.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot
Unrelated, undo this change.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Reverted the unrelated changes to this templatestrings.json file. All templatestrings.json files have been restored to their original state in commit 4536815.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot
Unrelated, undo this change.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Reverted the unrelated changes to this templatestrings.json file. All templatestrings.json files have been restored to their original state in commit 4536815.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot
Unrelated, undo this change.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Reverted the unrelated changes to this templatestrings.json file. All templatestrings.json files have been restored to their original state in commit 4536815.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot
Unrelated, undo this change.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Reverted the unrelated changes to this templatestrings.json file. All templatestrings.json files have been restored to their original state in commit 4536815.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot
Unrelated, undo this change.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Reverted the unrelated changes to this templatestrings.json file. All templatestrings.json files have been restored to their original state in commit 4536815.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot
Unrelated, undo this change.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Reverted the unrelated changes to this templatestrings.json file. All templatestrings.json files have been restored to their original state in commit 4536815.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot
Unrelated, undo this change.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Reverted the unrelated changes to this templatestrings.json file. All templatestrings.json files have been restored to their original state in commit 4536815.

…files

Co-authored-by: javiercn <6995051+javiercn@users.noreply.github.com>
@Copilot
Copy link
Contributor Author

Copilot AI commented Sep 15, 2025

@copilot you have work

All requested changes have been completed. Reverted all unrelated changes to cgmanifest.json and templatestrings.json files while preserving the core fix in Program.cs. The PR now only contains the essential change from UseStaticFiles() to MapStaticAssets() in commit 4536815.

@Copilot Copilot AI requested a review from javiercn September 15, 2025 14:31
Copilot finished work on behalf of javiercn September 15, 2025 14:31
@javiercn javiercn marked this pull request as ready for review September 16, 2025 13:34
@javiercn javiercn requested a review from a team as a code owner September 16, 2025 13:34
@Copilot Copilot AI review requested due to automatic review settings September 16, 2025 13:34
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR modernizes the Blazor MAUI Web template by replacing the legacy UseStaticFiles() middleware with the newer MapStaticAssets() approach for serving static assets in ASP.NET Core applications.

Key changes:

  • Removes app.UseStaticFiles() call from the middleware pipeline
  • Adds app.MapStaticAssets() call positioned before MapRazorComponents()
  • Updates the template to follow current ASP.NET Core best practices

@jsuarezruiz
Copy link
Contributor

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@mattleibow mattleibow merged commit 8b1ee20 into main Sep 18, 2025
20 checks passed
@mattleibow mattleibow deleted the copilot/fix-31617 branch September 18, 2025 15:04
mattleibow added a commit that referenced this pull request Sep 18, 2025
@mattleibow mattleibow restored the copilot/fix-31617 branch September 18, 2025 15:04
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

5 participants