-
Notifications
You must be signed in to change notification settings - Fork 195
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Basic Deployment Instructions for Avalonia WASM apps #320
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for improving the docs for the next person!!
I don't know why you had this issue, but it's wrong to use "dotnet build" for WASM production builds.
That's the issue. You don't execute webassembly app. It's a web site. It's need to be served on a static web server. Something like with https://github.com/natemcmaster/dotnet-serve (that's something we should mention in the docs for convenience). It's not suitable for production serving though, only to quickly run published. All you need is (assuming templates, SDK and dotnet-serve tool are already installed): mkdir wasmtest
cd wasmtest
dotnet new avalonia.xplat
cd wasmtest.Browser
dotnet publish
## At this point "dotnet" will output something like ` Generated app bundle at E:\wasmtest\wasmtest.Browser\bin\Release\net8.0\browser-wasm\AppBundle\`
cd E:\wasmtest\wasmtest.Browser\bin\Release\net8.0\browser-wasm\AppBundle\
dotnet serve
## Which will output something like Listening on any IP: http://localhost:62512 That's enough. Now, after you tested published bundle, you can copy AppBundle folder to your static web server of choice. Like Azure or GitHub Pages.
|
The problem with running "dotnet build" is that it's not a publishing semantically. Some optimizations or trimming might be disabled, output folder might contain build information unnecessary for production publishing. Even if it works, better to use more specific commands. |
I agree, that's why I got so caught up on In fact, now that I have tried your code I think there may be a bug in Will you please try the following code and tell me where you find the AppBundle folder in the output mkdir wasmtest
cd wasmtest
dotnet new avalonia.xplat
cd wasmtest.Browser
dotnet publish -o artifact |
@woojamon Seems like somebody opened issue there as well dotnet/runtime#94319 |
Thanks for your help and pointing out that message, @maxkatz6 ! I'll update the documentation, but I still think basic deployment instructions are needed. While I see that message and know what to do with AppBundle now, when I'm a newbie to Avalonia and trying to deploy even just the template project for the first time, how am I supposed to know that I need AppBundle, especially if it's not in my So I'll update the instructions to use |
@woojamon yeah. I think it would be great if this document mentioned:
|
@maxkatz6 you got it, let me make another commit. |
Done. |
Thank you! |
Added basic instructions to give a clue on how to deploy the wasm app to somewhere else.
Backstory:
While
dotnet run
is cool, I couldn't find any instructions on how to deploy my avalonia wasm app to get it up and running from the cloud.For more than two days I tried all possible flag variations of
dotnet publish -c Release -o artifact -r linux-x64/browser-wasm/osx-arm64 --self-contained
and then trying to execute themyApp.Browser.dll
file.I fought through many battles of
libhostpolicy.so: cannot open shared object file: No such file or directory
andlibhostpolicy.dylib: cannot open shared object file: No such file or directory
and then when I finally fought through all that I was able to execute the .dll without errors, but also without effect -- the program just exited.As it turns out, dotnet publish does not produce any AppBundle or any useful executable, at least that I could find. (I was just trying to deploy the starter wasm app from
dotnet new avalonia.xplat
.)So finally I got lucky and found a mention of dotnet-serve (https://github.com/natemcmaster/dotnet-serve) somewhere, and found that I could run my app locally from
artifact/AppBundle
usingdotnet serve -d:artifact/AppBundle
, but only if I built the app usingdotnet build -c Release -o artifact
.So then I tried to deploy dotnet-serve with my app to Azure Web Apps, but the underlying container wouldn't work with it and wouldn't let me
chmod
permissions on it so make it executable.Finally, I signed on to Telegram (https://docs.avaloniaui.net/docs/community) and got a tip from @MikeCodesDotNET that the current WASM samples are most likely deployed to Azure Static Web Apps.
As it turns out, I didn't need dotnet-serve at all, nor did I need to execute some .dll from the build output. I just needed to
build
(notpublish
) my app and point a web server to the AppBundle folder to serve it as a static site.Now finally on the fourth day I can start working on my app, since I now have a pipeline to get an app from local to the cloud.
Maybe I'm just dumb, but I hope no one else has to go through that horrible experience of figuring out how to do this. If I had even the simple clues that I'm adding in this pull request, I could have saved many days of frustration and toil and almost settling for some other framework!