aspnetcore icon indicating copy to clipboard operation
aspnetcore copied to clipboard

Blazor: Use of `--no-build` with `dotnet publish` breaks content with .NET 9 SDK

Open craigktreasure opened this issue 4 months ago • 3 comments

Is there an existing issue for this?

  • [x] I have searched the existing issues

Describe the bug

TLDR

  • Change in behavior for dotnet publish --no-build when using the .NET 9 SDK, which causes incorrectly named files in the wwwroot folder and breaks content.
  • When the jsmodules.publish.manifest.json resources are not named properly, there is no error indication as to what the problem is.

Explanation

Upon upgrading to use the .NET 9 SDK, my production endpoint began showing as blank. No errors in the console and no 404 errors retrieving resources. Inspecting the page, the body tag has a hidden-body class causing it to be...well...hidden. The loading-theme component also has mode="null", which isn't expected:

<loading-theme storage-name="theme">
  <fluent-design-theme mode="null" primary-color="Default"></fluent-design-theme>
</loading-theme>

If I remove the hidden-body class exposing the page, the theme is not correct. If I attempt to interact with the theme components, I start to see errors in the console:

Error: Microsoft.JSInterop.JSException: Cannot read properties of undefined (reading 'clearLocalStorage')
TypeError: Cannot read properties of undefined (reading 'clearLocalStorage')

None of this occurred building locally whether in or out of a container. I could, however, pull the production container produced by my CI and reproduce the issue.

After more head scratching than I'd care to admit, I discovered that my CI build does dotnet publish --no-build. After comparing the build artifacts, I discovered some files in the wwwroot folder that were different.

.NET 8 SDK with dotnet publish --no-build: • wwwroot/MyProjectName.modules.json

.NET 9 SDK with dotnet publish --no-build: • wwwroot/jsmodules.publish.manifest.json

.NET 9 SDK with dotnet publish (--no-build removed): • wwwroot/MyProjectName.modules.json

The contents of the json files are exactly the same.

It appears that something in .NET 9 SDK with regards to the use of --no-build has changed copying the files with unexpected names.

Workaround

Current workaround is to remove the use of the --no-build parameter for the publish command or rename the files yourself.

Expected Behavior

The MyProjectName.modules.json files should be produced in the publish output as expected.

dotnet build -c Release
# I typically run `dotnet test -c Release --no-build` here before publishing
dotnet publish --no-build # `dotnet publish` does Release configuration by default these days

The commands above should produce the wwwroot/MyProjectName.modules.json file rather than jsmodules.publish.manifest.json.

Using the .NET 8 SDK, everything worked as expected with the use of --no-build.

Steps To Reproduce

See https://github.com/craigktreasure/aspnet-58321-repro for a full repro of the issue.

Build a vanilla .NET 8 Fluent UI Blazor project using the following:

dotnet build -c Release
# I typically run `dotnet test -c Release --no-build` here before publishing
dotnet publish --no-build # `dotnet publish` does Release configuration by default these days

This will produce the wwwroot/jsmodules.publish.manifest.json file in the publish output.

Run the application and view the page to observe a visibly blank page.

Exceptions (if any)

No response

.NET Version

9.0.100-rc.1.24452.12 and 9.0.100-rc.2.24474.11

Anything else?

No response

craigktreasure avatar Oct 09 '24 16:10 craigktreasure