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: Set up a GitHub repository following the 'username.github.io' naming convention.
  2. Create/Existing Blazor WebAssembly App: Prepare your Blazor app for deployment.
  3. Deploying App Locally to Get Published Files: Deploy your Blazor app locally for testing.
  4. Test app locally (optional step): Test your app on IIS (Windows) or Apache (Linux, macOS, Windows).
  5. Publishing your files on Github-Pages: Clone your 'username.github.io' repository, add essential files, and push changes.
  6. Configure GitHub Pages: Enable GitHub Pages for your repository and make your website accessible on the internet.

Publish Your Personal Website

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.

. DeployingApp

Image 6. Publishing a web app through Visual Studio

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.

 target options to publish

Image 7. Selecting a 'Folder' option to publish a web app

At the end, simply browse to the folder where you want published files to be located.

 published files

Image 8. Browsing and selecting a folder for web app to be published

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.

 published files

Image 9. Published files

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.

wwwroot

Image 10. wwwroot folder

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)

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.

 clone repository button

Image 11. Clone repository

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.

 local machine.

Image 12. Cloning git repo into the 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.

published file

Image 13. "username.github.io" after hosted files

Now we just need to make a couple of changes, and you're good to go.

  1. First, add an empty file and give an extension of ".nojekyll":The .nojekyll file is a special file used in GitHub repositories, and its significance lies in its ability to control how GitHub Pages, the platform's static site hosting service, processes your repository's content. If you miss this file, you might get the error for loading BlazorWebAssebly.js​​​​.
  2. Update <base> Tag:In the index.html file of your Blazor app, you'll find a <base> tag that sets the base URL for your app. Update this tag to reflect the correct base URL for your GitHub Pages repository. In your case, for a repository named "username.github.io," the <base> tag should look like this.
    Base  tag
    Image 14. <Base> tag

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.

GitHub Pages

Image 15. GitHub pages settings

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.

gif

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!