dotnet / dotnet/aspnetcore

The "dotnet new mvc" template does not configure MapStaticAssets properly

Open
#59,152 3 comments 7 reactions 0 assignees View on GitHub
area-mvc feature-static-web-assets
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 5h
Merged PRs (30d)
276

Description

### Is there an existing issue for this?

- [x] I have searched the existing issues

### Describe the bug

The code that is generated by `dotnet new mvc` does not leave static assets served by `.MapStaticAssets()` in a properly functioning state.

The first and most serious issue is that the `.WithStaticAssets()` call does nothing because it is used on an overload of controller mapping that returns a builder that is missing an item that is needed to make `.WithStaticAssets()` work. This bug has been reported in #59003.

The second issue is that import maps will not work properly because the template is missing a `` tag in the `_Layout.cshtml`-file that is used as a point of reference for imports. This will prevent assets imported by scripts to be properly resolved.

### Expected Behavior

I expect `dotnet new mvc` to come set up with core features working properly.

### Steps To Reproduce

Generate a new project with `dotnet new mvc` and run it, you will see that assets are not properly fingerprinted in a `foo.hash.js` format like they should be but rather fingerprinted using the old `foo.js?v=hash` static file style and they don't have proper caching headers either.

Furthermore, code that is split into chunks by tools such as esbuild will not be loaded with fingerprinted URLes either because the importmap is ineffective due to the missing base-tag.

### Exceptions (if any)

_No response_

### .NET Version

9.0.100

### Anything else?

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.