Publish A Blazor Or Any Webapp On GitHub Pages For Free
Introduction
GitHub Pages provides a fantastic platform for hosting your Blazor web applications or any web-based project without any cost. In this comprehensive article, I'll walk you through the process of publishing a personal website, like the one I have as 'rikampalkar.github.io'. Throughout this journey, we'll cover everything from creating repositories, publishing applications locally, and pushing changes to the repository to configuring essential settings in GitHub Pages.
We will explore six essential steps to bring your personal website to life on the internet.
1. Creating a New Repository
2. Create/ExistingBlazor WebAssembly App
To get started with creating a Blazor WebAssembly app, you have two options: you can create a new app or use an existing one. If you want to learn how to create a new Blazor app, you can follow a detailed tutorial like the one provided in this article: Step-by-Step Guide to Develop Tic-Tac-Toe AI with Blazor.
Since this article focuses on publishing your Blazor app, we will assume that you already have a Blazor app ready for deployment. If you need guidance on creating a new Blazor app, please refer to the linked tutorial for comprehensive instructions.
3. DeployingApp Locally to get Published Files
In order to publish your app from Visual Studio, first right-click on your Blazor WebAssembly project (the one you want to publish) to open the context menu, then select the "Publish" buttons as shown in the below image.
Next, in the wizard, you'll come across multiple target options to publish your files in; for now, select "Folder" as we are testing this app locally.
At the end, simply browse to the folder where you want published files to be located.
Once you are satisfied with your settings, proceed by clicking the "Publish" button. Visual Studio will build your Blazor WebAssembly app and publish it to the specified location.
In my situation, the folder is named "Published code", and Visual Studio has organized two files (wwwroot folder and web. config file) as illustrated below.
If you open the "wwwroot" folder, you'll discover the heart of the app. These are the compiled files that should be uploaded to the GitHub repository (username.github.io) we've created in Step 1.
Recommended by LinkedIn
4. Test app locally (optional step)
Testing on Local Servers: IIS and Apache, choose your own battle; for Windows, follow step 1; for Mac and Linux, follow step 2.
1. Testing on IIS (Windows)
2. Testing on Apache (Linux, macOS, Windows)
sudo apt-get install apache2
sudo service apache2 restart
sudo apachectl start
You've now successfully created, tested, and hosted a Blazor WebAssembly app locally on both IIS and Apache servers. Now it's time to deploy your app on GitHubPages.
5. Publishing your files on Github-Pages
Clone repository in local machineIn this step, we begin by cloning the "username.github.io" repository (from step 1) to your local machine. I prefer using GitHub Desktop for this purpose, but you can also achieve this using the command line. To keep things straightforward, I'll demonstrate with GitHub Desktop. You can download this software from the official GitHub website.
In the app, click on the clone repository button, as shown below.
This will bring up a wizard, where you need to select "username.github.io" and then select the folder in the local machine where github will clone the repo from the server to your local machine.
Now the final step, copy files from the "wwwroot" folder from step 2 - image 10 to the folder you just cloned in image 12, and then simply push the changes into the repo.
If you've followed as mentioned, then your repository will look like this.
Now we just need to make a couple of changes, and you're good to go.
6. Configure GitHub Pages
To enable GitHub Pages for your repository, follow these steps, also highlighted in red color in image 15.
GitHub will build your Blazor app and host it on GitHub Pages; this take around 2-5 mins. Then simply refresh your page, and you'll see a link highlighted in green to your published site.
Now click on the link in blue color, and you'll be able to see the website hosted under url "username.github.io".
And there you have it, your very own piece of the web! To see my portfolio in action, visit my website at rikampalkar.github.io.
Conclusion
In this article, we have explored the process of publishing your personal website using GitHub Pages, specifically focusing on hosting Blazor web applications. We began by creating a repository following the naming convention 'username.github.io', which allows GitHub to recognize it as a dedicated GitHub Pages repository. Then, we discussed how to deploy your Blazor app locally and test it using various web servers, including IIS and Apache.
Finally, we learned how to publish your website on GitHub Pages, ensuring that it is accessible to the world. By following these steps, you can easily share your work and projects with a global audience. So, what are you waiting for? Get started and showcase your creations to the world!
Solutions Architect; Blazor/.NET/SQL full-scope (and full-stack) Developer
3moWhere's Image 14?