Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.3k views
in Technique[技术] by (71.8m points)

blazor hosted template project not working after publishing the app

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
question from:https://stackoverflow.com/questions/65870758/blazor-hosted-template-project-not-working-after-publishing-the-app

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...