C
C#2y ago
Turwaith

❔ Deploying a Blazor WebAssambly app.... but how??

I'm about to finish a front end that I have written in Blazor Wasm. Now I want to deploy it, so that I have a neat little folder with index.html in it as well as css, js, and pages folder. Just like if I'd built in in HTML and JS from scratch. Like your standard folder and file structure to host it on any simple webserver. Now I have tried using the Publish tab and published it to a folder. I've also tried using the console. But I only get some css and an index.html in that resulting folder that does nothing. None of my created pages are there. What am I doing wrong? I have not changed any project structure since creating the project from a wasm template
63 Replies
Turwaith
TurwaithOP2y ago
Do I need to move stuff into the wwwroot folder in my project structure? And if yes, how? Just drag and drop everything in? Does the Program.cs also go there?
Amos
Amos2y ago
@Turwaith You don't need to move anything anywhere. Since you're using WASM, I assume non-hosted? So you only have one project? If so, just build/publish it then execute the program. The program will start all the dependencies and host on whatever bind address you picked. Simply navigate to that address and there's your website.
Turwaith
TurwaithOP2y ago
Well technically it's a school project, and it's more about the back end (which is written in java, so totally different location). The front end (my blazor wasm) is not really gonna get rates, but it should work. So my teacher just needs to be able to start the website and use it. I was under the assumption that when building a blazor wasm project, I will in the end get a folder with the classic website structure, where you can just open index.html and everything works
Amos
Amos2y ago
Nothing changes, build/publish your project and execute the program
Turwaith
TurwaithOP2y ago
It's my first time using Blazor and a friend told me wasm was better for that use case than server Execute the program.... so there should be an exe lying around somewhere?
Angius
Angius2y ago
Blazor Server needs both the frontend and the server part, yes. WASM is just the frontend
Amos
Amos2y ago
After you publish it in Debug/publish/projectname.exe or Release/publish/projectname.exe (assuming Windows)
if you just build it, it'll be in the Debug or Release folder .../bin/netX.0/...
Angius
Angius2y ago
When I was deploying my Wasm app, the files I had to deploy were all under Long2Short/bin/Release/net5.0/publish/wwwroot/ Lemme dig that whole project up and see
Amos
Amos2y ago
You'd have had to publish the entire publish dir as dependencies though right? wwwroot is just SPA framework
Turwaith
TurwaithOP2y ago
There is a shit ton of dlls in that folder but no exe
Angius
Angius2y ago
Well... yeah
Amos
Amos2y ago
Published or Built? 😄
Angius
Angius2y ago
You can't run an exe in the browser
Turwaith
TurwaithOP2y ago
published
Angius
Angius2y ago
Blazor WASM works by running the .NET runtime in the browser with WASM It loads up the .dlls .exe is a Windows thing
Amos
Amos2y ago
Yeah, ZZZ correct if wrong, but I'm pretty sure you need to run the server-side since SPA can't be accessed from a static htm or whatever.
Angius
Angius2y ago
Of course it can
Turwaith
TurwaithOP2y ago
Yeah I know but I was just told by Ayymoss to look for an exe
Angius
Angius2y ago
Blazor WASM is just a regular ol' SPA page Like with Vue or React or what have you There's zero need for any sort of a server
Amos
Amos2y ago
What file would Tur need to run to access just the front end?
Angius
Angius2y ago
All of those files Then they'd need to run some sort of a local server to serve those static files Could be as simple as php -S localhost:5000 or whatever
Amos
Amos2y ago
;l Or just run the associated Blazor server with the WASM build 😄
Angius
Angius2y ago
Since the file:// protocol doesn't really let you load up external resources well I mean
Amos
Amos2y ago
Seems over complicated to run a separate server
Angius
Angius2y ago
If you have both the backend and the frontend, then sure
Amos
Amos2y ago
@Turwaith How did you create the project?
Angius
Angius2y ago
They can run the whole ASP.NET WebaAPI project, and that will serve the WASM frontend But from what I hear, this is just the WASM frontend
Amos
Amos2y ago
Yeah, I used Hosted WASM for my Blazor app and I run server-side stuff.
Angius
Angius2y ago
No server to speak of
Amos
Amos2y ago
ZZZZ are you familiar with OGP?
Angius
Angius2y ago
No clue what that is
Turwaith
TurwaithOP2y ago
Just the usual New project --> Blazor WebAssembly App
Amos
Amos2y ago
Open Graph Protocol 😦
Angius
Angius2y ago
Ah, the og:thumbnail metatag stuffs?
Amos
Amos2y ago
yaya Can you help me in #✅ Blazor WASM - Dynamic Open Graph Protocol ? @Turwaith Blazor WASM is server-side included
Amos
Amos2y ago
Amos
Amos2y ago
this is how I'm publishing it Okay - ZZZ's correct. I've never built a WASM non-hosted app before 😄
Angius
Angius2y ago
There's no server in question here, just the wasm app
Turwaith
TurwaithOP2y ago
Alright, look. I have a Java Spring Backend. That is the part of the school project that is being graded. The spring API is running on localhost on port 8080. I just need my front end to open the webpage I created in my wasm project and send the requests I programmed to this IP/port. Whatever it takes to achieve this ^^
Amos
Amos2y ago
You need to run a server, see ZZZ's php suggestion Out of curiosity, doesn't spring have front-end capabilities?
Angius
Angius2y ago
The gist is, you need to serve it somehow
Turwaith
TurwaithOP2y ago
I don't know ^^
Angius
Angius2y ago
With php server, spring, whatever
Turwaith
TurwaithOP2y ago
Okay so..... If I created this front end in raw html and javascript, I could just double click my index.html file, it opens in the browser and everything works. Now of course the browser understands javascript but obviously not C#. Is there no way of starting and using my front end just as easy as it were if I built it from scratch in html and javascript?
Angius
Angius2y ago
Does it work if you do it like that?
Turwaith
TurwaithOP2y ago
If I click the index.html that gets created here?
Angius
Angius2y ago
y
Turwaith
TurwaithOP2y ago
No it does not work. I know that ^^ I was wondering if there is a way to achieve exactly this somehow But it seems no
Angius
Angius2y ago
theres your answer you can make spring serve it tho probably just like it would serve a react spa or we
Turwaith
TurwaithOP2y ago
Alright thanks. Now I need to find out how to do this ^^
Amos
Amos2y ago
Would it be worth moving your stuff to a Blazor Hosted application?
Angius
Angius2y ago
probably not
Turwaith
TurwaithOP2y ago
Nah I spent like 1h on that front end, most of its logic written by ChatGPT even. I didn't want to bother with javascript just for a school project where the front end doesn't even really matter that much, so I thought I'm gonna to it in Blazor since I already know C# Thought that would be simpler
Amos
Amos2y ago
Based. 😄
Turwaith
TurwaithOP2y ago
Turns out: Not necessarily, looking at my problems right now
Amos
Amos2y ago
I'm working on my biggest project and it's all in Blazor Hosted. Front and Back, so far very happy with no Javascript. It's a blessing
Turwaith
TurwaithOP2y ago
Yeah, if there were really a using of my project I would love to just deploy it onto some service that can handle wasm projects. But since I want something that I can just send to the teacher and he can just open and use it..... seems to me that blazor was like the worst possible choice for that ^^ Maybe I need to tell him to just download visual studio real quick and open it inside there. That's probably the easiest way
Angius
Angius2y ago
uh Downloading the .NET SDK and dotnet run on your project will be much faster
Turwaith
TurwaithOP2y ago
hang on Wow that's genius I will just tell him that :D Thanks for the help :D It was literally all I needed for this purpose ^^
Angius
Angius2y ago
Just make sure it's the appropriate version Won't be able to run a .NET 7 project using .NET 6 SDK
Turwaith
TurwaithOP2y ago
Yeah I tell him to download version 7 All that should work on linux too right, including the command dotnet run? And if it doesn't I don't care anymore, he will be able to somehow get his hands on a windows machine
Angius
Angius2y ago
Yeah, should work on Linux just fine
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server