1

I create a new blazor hosted project, named foo, from the dotnet CLI:

dotnet new blazorwasm --hosted

I run the app with

dotnet run -c Release

The template app works correctly when requesting https://localhost:5001 (or 5000)

I then publish the app with:

dotnet publish -c Release

And then try to launch it with

dotnet Server/bin/Release/net5.0/publish/foo.Server.dll

I expect the app to lanch correctly. But I actually get a 404 response. Why is that ?

Notes:

  • It was working properly few days ago.
  • When publishing, we get the message "Optimizing assemblies for size, which may change the behavior of the app. Be sure to test after publishing. See: https://aka.ms/dotnet-illink". I don't think this has anything to do with my issue as it was working properly before.
  • I'm on Windows 10, dotnet sdk version 5.0.102
Abdelhakim
  • 815
  • 1
  • 5
  • 19

1 Answers1

3

Blazor WASM Hosted project has three projects: client, server and shared. To publish the solution as a one publish site, run the command

dotnet publish MyWasmSolution.sln -C Release --output .\publish

The publish folder contain all DLLs of server/client and shared and wwwroot of both server and client including blazor.webassembly.js with all compressed file.

Then, move to the publish folder (the Content root, because dotnet run consider the current folder as the Content root).

Run the next script:

cd path/to/folder/publish
dotnet foo.Server.dll

The index.html is loaded in the browser and if you click F12 (dev tools) you find no errors.

M.Hassan
  • 10,282
  • 5
  • 65
  • 84
  • `dotnet Server/bin/Release/net5.0/publish/foo.Server.dll` is equivalent to `cd Server/bin/Release/net5.0/publish` and then `dotnet foo.Server.dll` – Abdelhakim Jan 24 '21 at 15:47
  • 1
    Please, have a look to Content root for both cases when you run the command . They are different, because `dotnet run ' consider the current folder is the content root, and really it's not. – M.Hassan Jan 24 '21 at 15:52
  • 1
    The content root effectively changes depending on what folder the dotnet command is executed in (It never caught my attention) thanks. Now I have the index.html returnred but still the app doesn't launch because the request for blazor.webassembly.js `https://localhost:5001/_framework/blazor.webassembly.js` returns a 404 response. I checked the `_framework/` folder and the file is missing. is that a normal behaviour again. Why doesn't the publish command put it there ? – Abdelhakim Jan 24 '21 at 16:12
  • It seems the client wwwroot is not available for the server. I'll update my answer to show how to publish as one site. – M.Hassan Jan 24 '21 at 16:35
  • the client wwwroot/ folder is present in the published app (index.html, all the styles and icons...etc). Only the blazor.webassembly.js is missing. Waiting for your update :) thanks. – Abdelhakim Jan 24 '21 at 16:54
  • Your updated answer suggests to specify the output folder (./publish). I did that and the app now works perfectly. This is weird because the output parameter is optional. The publish command should have the same output whether I specify or not the output folder. But it doesn't. – Abdelhakim Jan 24 '21 at 17:12
  • 1
    Vs 2019 publish three projects under bin folder (not one) and assume that you use `dotnet run ` the project :) and host both client and server. – M.Hassan Jan 24 '21 at 17:21
  • Right. When I have a project A that depends on a project B, and I publish A, both A and B will be published in their respective bin projects. But the published A will also contain the published files from B (I can see B.dll files in /A/bin/Releaase/publish). I can move only the publish folder from A to another location and still have the app working. This seems to be different with blazor just because of this wwwroot/ folder. I'm I right ? – Abdelhakim Jan 24 '21 at 18:19
  • 1
    You are right, blazor hosted has special case. When publish to one output, wwroot of both client and server are merged together in one wwroot and so you host only one site. Notice the the message of the publish for both publish commands with/o output option. – M.Hassan Jan 24 '21 at 18:40