aspnetcore
aspnetcore copied to clipboard
Blazor: Use of `--no-build` with `dotnet publish` breaks content with .NET 9 SDK
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-buildwhen using the .NET 9 SDK, which causes incorrectly named files in thewwwrootfolder and breaks content. - When the
jsmodules.publish.manifest.jsonresources 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
@javiercn I have added a minimal repro at https://github.com/craigktreasure/aspnet-58321-repro.
@craigktreasure thanks for the additional details.
Found the issue. Was likely moved into a target, and doesn't get set if the --no-build flag is present. To workaround this issue you can simply set it on your csproj the same way we do (see below).
<JSModuleManifestRelativePath Condition="'$(JSModuleManifestRelativePath)' == ''">$(PackageId).modules.json</JSModuleManifestRelativePath>
This should take care of it https://github.com/dotnet/sdk/pull/44160
Fixed by https://github.com/dotnet/sdk/pull/44160
@javiercn will this be backported to .NET 9 SDK? This breaks our .NET 8 application.
@Bouke are you saying that the fix in https://github.com/dotnet/aspnetcore/issues/58321#issuecomment-2411598004 doesn't work for you?
If so, can you file a separate issue and provide a repro? Note that you can also call publish instead of publish --no-build
@javiercn it doesn't work; the published file is named .modules.json. I'm now testing this workaround:
<PropertyGroup Label=".NET 9 SDK shenanigans">
<JSModuleManifestRelativePath Condition="'$(JSModuleManifestRelativePath)' == ''">$(AssemblyName).modules.json</JSModuleManifestRelativePath>
</PropertyGroup>
Agree. This is not a new issue. The original issue is not fixed. I've updated my repro to the .NET 9.0.100 SDK and the issue still exists.
I just updated my app from .NET 8 to .NET 9 and ran into this issue. Are you guys sure this is fixed?
Just tried the workaround proposed here, but unforunately I get the same result as @Bouke above.
Using $(PackageId) I also get this result:
@javiercn Can you reopen this issue please? It doesn't appear to have been fixed.
Same error here, I have upgraded my net8 to net9.
That does not solve the issue :(
<JSModuleManifestRelativePath Condition="'$(JSModuleManifestRelativePath)' == ''">$(PackageId).modules.json</JSModuleManifestRelativePath>
@craigktreasure for now I'm using MSBuildProjectName:
<JSModuleManifestRelativePath Condition="'$(JSModuleManifestRelativePath)' == ''">$(MSBuildProjectName).modules.json</JSModuleManifestRelativePath>
That fixed the issue.