---
title: "How to deploy Blazor WebAssembly to Firebase Hosting"
excerpt: "With ASP.NET Blazor WebAssembly you can create .NET applications that run completely inside of the browser. The output of a Blazor WASM project are all static files. You can deploy these applications to various static site hosts like Firebase Hosting."
publishDate: "2020-12-27T00:00:00"
createDate: "2020-12-19T06:45:34.087"
updateDate: "2021-04-02T23:32:37.497"
category: "dotnet"
categoryName: ".NET"
tags: [".NET","dotnet",".NET Core","dotnetcore","ASP.NET","aspnet","ASP.NET Core","aspnetcore","Blazor","C#","csharp","Firebase","GitHub"]
permalink: "/blog/dotnet/how-to-deploy-blazor-webassembly-to-firebase-hosting"
canonical: "/blog/dotnet/how-to-deploy-blazor-webassembly-to-firebase-hosting"
image: {"src":"/media/yr2dc0fo/blazor-github-firebase-long.png","focalPoint":{"left":0.5,"top":0.4993280071679235},"crops":[{"alias":"Banner","width":1120,"height":400,"coordinates":null}]}
imageAlt: "Title: How to deploy Blazor WebAssembly to Firebase Hosting. Blazor logo next to an arrow pointing to the GitHub logo next to a double arrow pointing from the GitHub logo to the Firebase Hosting logo "
imageBackgroundColor: "#fff"
thumbnailImage: {"src":"/media/sabcadlf/blazor-github-firebase-square.png","focalPoint":{"left":0.5,"top":0.5},"crops":[{"alias":"thumbnail","width":250,"height":250,"coordinates":null}]}
thumbnailImageAlt: " Blazor logo next to an arrow pointing to the GitHub logo next to a double arrow pointing from the GitHub logo to the Firebase Hosting logo "
metaTitle: "How to deploy Blazor WebAssembly to Firebase Hosting"
metaDescription: "With ASP.NET Blazor WebAssembly you can create .NET applications that run completely inside of the browser. The output of a Blazor WASM project are all static files. You can deploy these applications to various static site hosts like Firebase Hosting."
ogTitle: "How to deploy Blazor WebAssembly to Firebase Hosting"
ogDescription: "With ASP.NET Blazor WebAssembly you can create .NET applications that run completely inside of the browser. The output of a Blazor WASM project are all static files. You can deploy these applications to various static site hosts like Firebase Hosting."
ogImage: {"src":"/media/0djjgd2r/blazor-github-firebase-social.png","focalPoint":{"left":0.5,"top":0.501507697190922},"crops":[{"alias":"OpenGraph","width":1200,"height":630,"coordinates":null}]}
ogImageAlt: "Title: How to deploy Blazor WebAssembly to Firebase Hosting. Blazor logo next to an arrow pointing to the GitHub logo next to a double arrow pointing from the GitHub logo to the Firebase Hosting logo "
relatedPostKeys: ["3fa142faee1a488c91f507627e8059bb","b01d783c18284f05b29774abcd096471"]
noIndex: false
noFollow: false
sitemapExclude: false
headHtml: |-
  <script type="application/ld+json">{
    "@context": "http://schema.org",
    "@type": "VideoObject",
    "name": "How to Deploy Blazor WebAssembly to Firebase Hosting",
    "description": "With ASP.NET Blazor WebAssembly you can create .NET applications that run completely inside of the browser. The output of a Blazor WASM project are all static files. You can deploy these applications to various static site hosts like Firebase Hosting. This video will show you how to: - Create a Blazor WASM project - Create a GitHub repository - Deploy to Firebase Hosting from the CLI - Automatically deploy to Firebase Hosting using GitHub Actions  For more content on .NET, Web Development, Azure, and more, check out https://swimburger.net. Follow me on Twitter @RealSwimburger: https://twitter.com/RealSwimburger  You can also learn how to deploy Blazor WASM to Firebase by following the tutorial on swimburger.net: https://swimburger.net/blog/dotnet/how-to-deploy-blazor-webassembly-to-firebase-hosting  You can also learn how to deploy Blazor WASM to GitHub Pages by following this tutorial on swimburger.net: https://swimburger.net/blog/dotnet/how-to-deploy-aspnet-blazor-webassembly-to-github-pages  To learn how to deploy Blazor WASM and Azure Functions to Azure Static Web Apps, check out this tutorial on swimburger.net: https://swimburger.net/blog/dotnet/how-to-deploy-aspnet-blazor-webassembly-to-azure-static-web-apps   ► Music Credit: 'Low Frequency Music'  Track Name: 'Opportunity'  Music By: Low Frequency Music @ https://soundcloud.com/user-551516820  Official \"Low Frequency Music\" YouTube Channel HERE - https://www.youtube.com/LowFrequencyMusic  License for commercial use: Creative Commons Attribution 3.0 Unported \"Share Alike\" (CC BY-SA 3.0) License. Full License HERE - https://creativecommons.org/licenses/by-sa/3.0/legalcode  Music promoted by NCM https://goo.gl/fh3rEJ@ www.ChillOutMedia.com / www.LoFi-HipHop.com",
    "thumbnailUrl": "https://i.ytimg.com/vi/8a5Pz3oZzNY/default.jpg",
    "uploadDate": "2021-01-21T19:00:10Z",
    "duration": "PT16M9S",
    "embedUrl": "https://www.youtube.com/embed/8a5Pz3oZzNY"
  }</script>
source: {"nodeId":1387,"contentKey":"0d375026e40743fdadc9c3b841802a6a","sortOrder":72}
---

<p>With ASP.NET Blazor WebAssembly (WASM) you can create .NET web applications that run completely inside of the browser sandbox. The publish output of a Blazor WASM project are <strong>all static files</strong>. Now that you can run .NET web applications without server side code, you can deploy these application to various <strong>static site hosts, such as Google's Firebase Hosting</strong>.</p>
<p>Here's some other tutorials if you're interested in hosting Blazor WASM on other static site hosts:</p>
<ul>
<li><a href="https://swimburger.net/blog/dotnet/how-to-deploy-aspnet-blazor-webassembly-to-azure-static-web-apps">Azure Static Web Apps using GitHub</a></li>
<li><a href="https://daveabrock.com/2021/04/01/static-web-apps-azure-pipelines">Azure Static Web Apps using Azure DevOps (by Dave Brock)</a></li>
<li><a href="/blog/dotnet/how-to-deploy-blazor-webassembly-to-aws-amplify" type="document" title="How to deploy Blazor WebAssembly to AWS Amplify">AWS Amplify</a></li>
<li><a href="/blog/dotnet/how-to-deploy-blazor-webassembly-to-netlify" type="document" title="How to deploy Blazor WebAssembly to Netlify">Netlify</a></li>
<li><a href="/blog/dotnet/how-to-deploy-blazor-webassembly-to-cloudflare-pages" type="document" title="How to deploy Blazor WebAssembly to Cloudflare Pages" data-anchor="#">Cloudflare Pages</a></li>
<li><a href="/blog/dotnet/how-to-deploy-blazor-webassembly-to-digitalocean-app-platform" type="document" title="How to deploy Blazor WebAssembly to DigitalOcean App Platform">DigitalOcean App Platform</a></li>
<li><a href="/blog/dotnet/how-to-deploy-blazor-webassembly-to-heroku" type="document" title="How to deploy Blazor WebAssembly to Heroku">Heroku</a></li>
<li><a href="https://swimburger.net/blog/dotnet/how-to-deploy-aspnet-blazor-webassembly-to-github-pages">GitHub Pages</a><a href="/blog/dotnet/how-to-deploy-blazor-webassembly-to-aws-amplify" type="document" title="How to deploy Blazor WebAssembly to AWS Amplify"></a><a href="https://swimburger.net/blog/dotnet/how-to-deploy-blazor-webassembly-to-firebase-hosting"></a></li>
</ul>
<p><strong>If you prefer video content, you can learn how to manually deploy Blazor WASM to Firebase Hosting and how to automate it using GitHub Actions on this YouTube video:</strong></p>
<div class='embed-container'><iframe src='https://www.youtube.com/embed/8a5Pz3oZzNY' allowfullscreen title="YouTube video player" loading="lazy"></iframe></div>
<p>This walkthrough will show you how to deploy Blazor WASM to Firebase Hosting manually and using GitHub Actions. Make sure to review the <a rel="noopener" href="https://firebase.google.com/pricing#hosting" target="_blank" title="Firebase Hosting Pricing" data-anchor="#hosting">restrictions of Firebase's free plan called "Spark"</a>.</p>
<p>This how-to will walk you through these high-level steps:</p>
<ol style="margin-bottom: 30px;">
<li>Create Blazor WebAssembly project</li>
<li>Commit the project to a Git repository</li>
<li>Create a new GitHub project and push the Git repository to GitHub</li>
<li>Initialize Firebase in your project</li>
<li>Deploy to Firebase Hosting manually</li>
<li>Deploy using GitHub Actions workflow</li>
</ol>
<p><strong>Prerequisites</strong>:</p>
<ul>
<li>.NET Core 3.1 or above</li>
<li>Git</li>
<li>GitHub account</li>
<li>Firebase CLI (<a rel="noopener" href="https://firebase.google.com/docs/cli" target="_blank" title="Firebase CLI reference">installation instructions</a>)</li>
</ul>
<p class="panel panel--info"><strong>You can refer to the code used throughout this walkthrough in <a rel="noopener" href="https://github.com/Swimburger/FirebaseHostingBlazorWasm" target="_blank">this GitHub repository</a>.</strong></p>
<h2 id="create-aspnet-core-blazor-webassembly-project">Create Blazor WebAssembly project</h2>
<p>Run the following commands to create a new Blazor WASM project:</p>
<pre style="color:#000000;background:#ffffff;">mkdir <span style="color:#2a00ff; ">FirebaseHostingBlazorWasm</span> &#10;cd <span style="color:#2a00ff; ">FirebaseHostingBlazorWasm</span> &#10;dotnet <span style="color:#2a00ff; ">new</span> <span style="color:#2a00ff; ">blazorwasm</span> -n <span style="color:#2a00ff; ">BlazorWasmSample</span> -o <span style="color:#2a00ff; ">src</span>&#10;</pre>
<p>In this tutorial the Blazor WASM project is purposely put into the <em>src</em> subfolder to keep source code separate from other assets.</p>
<p>To give your application a try, execute <code>dotnet run</code> and browse to the URL in the output (probably <a href="https://localhost:5001/">https://localhost:5001</a>):</p>
<pre style="color:#000000;background:#ffffff;">dotnet <span style="color:#2a00ff; ">run</span> -p <span style="color:#2a00ff; ">src/BlazorWasmSample.csproj</span>&#10;<span style="color:#3f7f59; "># Building...</span>&#10;<span style="color:#3f7f59; "># info: Microsoft.Hosting.Lifetime[0]</span>&#10;<span style="color:#3f7f59; ">#       Now listening on: </span><span style="color:#3f3fbf; ">https://localhost:5001</span>&#10;<span style="color:#3f7f59; "># info: Microsoft.Hosting.Lifetime[0]</span>&#10;<span style="color:#3f7f59; ">#       Now listening on: </span><span style="color:#3f3fbf; ">http://localhost:5000</span>&#10;<span style="color:#3f7f59; "># info: Microsoft.Hosting.Lifetime[0]</span>&#10;<span style="color:#3f7f59; ">#       Application started. Press Ctrl+C to shut down.</span>&#10;<span style="color:#3f7f59; "># info: Microsoft.Hosting.Lifetime[0]</span>&#10;<span style="color:#3f7f59; ">#       Hosting environment: Development</span>&#10;<span style="color:#3f7f59; "># info: Microsoft.Hosting.Lifetime[0]</span>&#10;<span style="color:#3f7f59; ">#       Content root path: C:\Users\niels\source\repos\FirebaseHostingBlazorWasm\src</span>&#10;<span style="color:#3f7f59; "># info: Microsoft.Hosting.Lifetime[0]</span>&#10;<span style="color:#3f7f59; ">#       Application is shutting down...</span>&#10;</pre>
<p>Optional: You can use the <code>dotnet publish</code> command to publish the project and verify the output:</p>
<pre style="color:#000000;background:#ffffff;">dotnet <span style="color:#2a00ff; ">publish</span> <span style="color:#2a00ff; ">src/BlazorWasmSample.csproj</span>&#10;<span style="color:#3f7f59; "># Microsoft (R) Build Engine version 16.8.0+126527ff1 for .NET</span>&#10;<span style="color:#3f7f59; "># Copyright (C) Microsoft Corporation. All rights reserved.</span>&#10;<span style="color:#3f7f59; "># </span>&#10;<span style="color:#3f7f59; ">#   Determining projects to restore...</span>&#10;<span style="color:#3f7f59; ">#   All projects are up-to-date for restore.</span>&#10;<span style="color:#3f7f59; ">#   BlazorWasmSample -&gt; C:\Users\niels\source\repos\FirebaseHostingBlazorWasm\src\bin\Debug\net5.0\BlazorWasmSample.dll</span>&#10;<span style="color:#3f7f59; ">#   BlazorWasmSample (Blazor output) -&gt; C:\Users\niels\source\repos\FirebaseHostingBlazorWasm\src\bin\Debug\net5.0\wwwroot  Optimizing assemblies for size, which may change the behavior of the app. Be sure to test after publishing. See: </span><span style="color:#3f3fbf; ">https://aka.ms/dotnet-illink</span>&#10;<span style="color:#3f7f59; ">#   Compressing Blazor WebAssembly publish artifacts. This may take a while...</span>&#10;<span style="color:#3f7f59; ">#   BlazorWasmSample -&gt; C:\Users\niels\source\repos\FirebaseHostingBlazorWasm\src\bin\Debug\net5.0\publish\</span>&#10;</pre>
<p>In the publish directory, you will find a web.config file and a wwwroot folder. The config file helps you host your application in IIS, but you don't need that file for static site hosts. <strong>Everything you need will be inside of the wwwroot folder. The wwwroot folder contains the index.html, CSS, JS, and DLL files necessary to run the Blazor application</strong>.</p>
<h2 id="push-blazor-project-to-github">Push Blazor project to GitHub</h2>
<p>For this walkthrough, your application source code must be inside of a GitHub repository.<br>First, you need to create a local Git repository and commit your source code to the repository using these commands:</p>
<pre style="color:#000000;background:#ffffff;"><span style="color:#3f7f59; "># add the gitignore file tailored for dotnet applications, this will ignore bin/obj and many other non-source code files </span>&#10;dotnet <span style="color:#2a00ff; ">new</span> <span style="color:#2a00ff; ">gitignore</span> -o <span style="color:#2a00ff; ">src</span>&#10;<span style="color:#3f7f59; "># create the git repository </span>&#10;git <span style="color:#2a00ff; ">init</span> &#10;<span style="color:#3f7f59; "># track all files that are not ignore by .gitignore </span>&#10;git <span style="color:#2a00ff; ">add</span> <span style="color:#2a00ff; ">--all</span> &#10;<span style="color:#3f7f59; "># commit all changes to the repository</span>&#10;git <span style="color:#2a00ff; ">commit</span> -m <span style="color:#2a00ff; ">"</span><span style="color:#2a00ff; ">Initial commit</span><span style="color:#2a00ff; ">"</span>&#10;</pre>
<p>Create a new GitHub repository (<a rel="noopener" href="https://docs.github.com/en/github/getting-started-with-github/create-a-repo" target="_blank">instructions</a>) and copy the commands to "push an existing repository from the command line" from the empty GitHub repository page, here's what it should looks like but with a different URL:</p>
<pre style="color:#000000;background:#ffffff;">git <span style="color:#2a00ff; ">remote</span> <span style="color:#2a00ff; ">add</span> <span style="color:#2a00ff; ">origin</span> <span style="color:#2a00ff; ">https://github.com/Swimburger/FirebaseHostingBlazorWasm.git</span> &#10;git <span style="color:#2a00ff; ">push</span> -u <span style="color:#2a00ff; ">origin</span> <span style="color:#2a00ff; ">main</span>&#10;</pre>
<h2 id="create-a-github-actions-workflow">Initialize Firebase in your project</h2>
<p>Make sure you have <a rel="noopener" href="https://firebase.google.com/docs/cli" target="_blank">installed the Firebase CLI and that you are logged in</a>. Then run <code>firebase init</code>:</p>
<pre style="color:#000000;background:#ffffff;">firebase <span style="color:#2a00ff; ">init</span>&#10;<span style="color:#3f7f59; "># output with prompts below:</span>&#10;<span style="color:#3f7f59; ">&lt;# </span>&#10;<span style="color:#3f7f59; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;######## #### ########  ######## ########     ###     ######  ########</span>&#10;<span style="color:#3f7f59; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;##        ##  ##     ## ##       ##     ##  ##   ##  ##       ##</span>&#10;<span style="color:#3f7f59; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;######    ##  ########  ######   ########  #########  ######  ######</span>&#10;<span style="color:#3f7f59; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;##        ##  ##    ##  ##       ##     ## ##     ##       ## ##</span>&#10;<span style="color:#3f7f59; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;##       #### ##     ## ######## ########  ##     ##  ######  ########</span>&#10;<span style="color:#3f7f59; "></span>&#10;<span style="color:#3f7f59; ">You're about to initialize a Firebase project in this directory:</span>&#10;<span style="color:#3f7f59; "></span>&#10;<span style="color:#3f7f59; ">&nbsp;&nbsp;C:\Users\niels\source\repos\FirebaseHostingBlazorWasm</span>&#10;<span style="color:#3f7f59; "></span>&#10;<span style="color:#3f7f59; ">? Are you ready to proceed? Yes</span>&#10;<span style="color:#3f7f59; ">? Which Firebase CLI features do you want to set up for this folder? Press Space to select features, then Enter to confirm your choices. Hosting: Configure and deploy Firebase Hosting sites</span>&#10;<span style="color:#3f7f59; "></span>&#10;<span style="color:#3f7f59; ">=== Project Setup</span>&#10;<span style="color:#3f7f59; "></span>&#10;<span style="color:#3f7f59; ">First, let's associate this project directory with a Firebase project.</span>&#10;<span style="color:#3f7f59; ">You can create multiple project aliases by running firebase use --add,</span>&#10;<span style="color:#3f7f59; ">but for now we'll just set up a default project.</span>&#10;<span style="color:#3f7f59; "></span>&#10;<span style="color:#3f7f59; ">? Please select an option: Create a new project</span>&#10;<span style="color:#3f7f59; ">i  If you want to create a project in a Google Cloud organization or folder, please use "firebase projects:create" instead, and return to this command when you've created the project.</span>&#10;<span style="color:#3f7f59; ">? Please specify a unique project id (warning: cannot be modified afterward) [6-30 characters]: blazor-wasm-sample2</span>&#10;<span style="color:#3f7f59; ">? What would you like to call your project? (defaults to your project ID)</span>&#10;<span style="color:#3f7f59; ">√ Creating Google Cloud Platform project</span>&#10;<span style="color:#3f7f59; ">√ Adding Firebase resources to Google Cloud Platform project</span>&#10;<span style="color:#3f7f59; "></span>&#10;<span style="color:#3f7f59; ">=== Your Firebase project is ready! ===</span>&#10;<span style="color:#3f7f59; "></span>&#10;<span style="color:#3f7f59; ">Project information:</span>&#10;<span style="color:#3f7f59; ">&nbsp;&nbsp;&nbsp;- Project ID: blazor-wasm-sample2</span>&#10;<span style="color:#3f7f59; ">&nbsp;&nbsp;&nbsp;- Project Name: blazor-wasm-sample2</span>&#10;<span style="color:#3f7f59; "></span>&#10;<span style="color:#3f7f59; ">Firebase console is available at</span>&#10;<span style="color:#3f3fbf; ">https://console.firebase.google.com/project/blazor-wasm-sample2/overview</span><span style="color:#3f7f59; "></span>&#10;<span style="color:#3f7f59; ">i  Using project blazor-wasm-sample2 (blazor-wasm-sample2)</span>&#10;<span style="color:#3f7f59; "></span>&#10;<span style="color:#3f7f59; ">=== Hosting Setup</span>&#10;<span style="color:#3f7f59; "></span>&#10;<span style="color:#3f7f59; ">Your public directory is the folder (relative to your project directory) that</span>&#10;<span style="color:#3f7f59; ">will contain Hosting assets to be uploaded with firebase deploy. If you</span>&#10;<span style="color:#3f7f59; ">have a build process for your assets, use your build's output directory.</span>&#10;<span style="color:#3f7f59; "></span>&#10;<span style="color:#3f7f59; ">? What do you want to use as your public directory? release/wwwroot</span>&#10;<span style="color:#3f7f59; ">? Configure as a single-page app (rewrite all urls to /index.html)? Yes</span>&#10;<span style="color:#3f7f59; ">? Set up automatic builds and deploys with GitHub? Yes</span>&#10;<span style="color:#3f7f59; ">+  Wrote release/wwwroot/index.html</span>&#10;<span style="color:#3f7f59; "></span>&#10;<span style="color:#3f7f59; ">i  Didn't detect a .git folder. Assuming C:\Users\niels\source\repos\FirebaseHostingBlazorWasm is the project root.</span>&#10;<span style="color:#3f7f59; ">i  Authorizing with GitHub to upload your service account to a GitHub repository's secrets store.</span>&#10;<span style="color:#3f7f59; "></span>&#10;<span style="color:#3f7f59; ">Visit this URL on this device to log in:</span>&#10;<span style="color:#3f7f59; ">[REDACTED]</span>&#10;<span style="color:#3f7f59; "></span>&#10;<span style="color:#3f7f59; ">Waiting for authentication...</span>&#10;<span style="color:#3f7f59; "></span>&#10;<span style="color:#3f7f59; ">+  Success! Logged into GitHub as Swimburger</span>&#10;<span style="color:#3f7f59; "></span>&#10;<span style="color:#3f7f59; ">? For which GitHub repository would you like to set up a GitHub workflow? (format: user/repository) Swimburger/FirebaseHostingBlazorWasm</span>&#10;<span style="color:#3f7f59; "></span>&#10;<span style="color:#3f7f59; ">+  Created service account github-action-322735214 with Firebase Hosting admin permissions.</span>&#10;<span style="color:#3f7f59; ">+  Uploaded service account JSON to GitHub as secret FIREBASE_SERVICE_ACCOUNT_BLAZOR_WASM_SAMPLE2.</span>&#10;<span style="color:#3f7f59; ">i  You can manage your secrets at </span><span style="color:#3f3fbf; ">https://github.com/Swimburger/FirebaseHostingBlazorWasm/settings/secrets</span><span style="color:#3f7f59; ">.</span>&#10;<span style="color:#3f7f59; "></span>&#10;<span style="color:#3f7f59; ">? Set up the workflow to run a build script before every deploy? Yes</span>&#10;<span style="color:#3f7f59; ">? What script should be run before every deploy? dotnet publish -c Release -o release</span>&#10;<span style="color:#3f7f59; "></span>&#10;<span style="color:#3f7f59; ">+  Created workflow file C:\Users\niels\source\repos\FirebaseHostingBlazorWasm\.github/workflows/firebase-hosting-pull-request.yml</span>&#10;<span style="color:#3f7f59; ">? Set up automatic deployment to your site's live channel when a PR is merged? Yes</span>&#10;<span style="color:#3f7f59; ">? What is the name of the GitHub branch associated with your site's live channel? main</span>&#10;<span style="color:#3f7f59; "></span>&#10;<span style="color:#3f7f59; ">+  Created workflow file C:\Users\niels\source\repos\FirebaseHostingBlazorWasm\.github/workflows/firebase-hosting-merge.yml</span>&#10;<span style="color:#3f7f59; "></span>&#10;<span style="color:#3f7f59; ">i  Action required: Visit this URL to revoke authorization for the Firebase CLI GitHub OAuth App:</span>&#10;<span style="color:#3f3fbf; ">https://github.com/settings/connections/applications/89cf50f02ac6aaed3484</span><span style="color:#3f7f59; "></span>&#10;<span style="color:#3f7f59; ">i  Action required: Push any new workflow file(s) to your repo</span>&#10;<span style="color:#3f7f59; "></span>&#10;<span style="color:#3f7f59; ">i  Writing configuration info to firebase.json...</span>&#10;<span style="color:#3f7f59; ">i  Writing project information to .firebaserc...</span>&#10;<span style="color:#3f7f59; ">i  Writing gitignore file to .gitignore...</span>&#10;<span style="color:#3f7f59; "></span>&#10;<span style="color:#3f7f59; ">+  Firebase initialization complete! </span>&#10;<span style="color:#3f7f59; ">#&gt;</span>&#10;</pre>
<p>The CLI will take you through initializing Firebase locally step by step. You can see the output above. Provide the following responses to the prompt:</p>
<ul>
<li>Are you ready to proceed? <strong>Yes</strong></li>
<li>Which Firebase CLI features do you want to set up for this folder? Press Space to select features, then Enter to confirm your choices.<br><strong>Select hosting and then press enter.</strong></li>
<li>First, let's associate this project directory with a Firebase project. You can create multiple project aliases by running firebase use --add, but for now we'll just set up a default project.<br><strong>Create a new project</strong><br>
<ul>
<li>Please specify a unique project id (warning: cannot be modified afterward) [6-30 characters]:<br><strong>[your-username]-blazor-wasm-sample<br></strong><em>The project id has to be globally unique.</em></li>
<li>What would you like to call your project? (defaults to your project ID)<br><strong>Accept default or provide a project name.</strong></li>
</ul>
</li>
<li>What do you want to use as your public directory?<br><strong>release/wwwroot<br></strong><em>You'll publish the Blazor WASM project to the release folder later.</em></li>
<li>Configure as a single-page app (rewrite all urls to /index.html)? <br><strong>Yes</strong></li>
<li>Set up automatic builds and deploys with GitHub? <br><strong>Yes</strong></li>
<li>Give Firebase permissions to access your GitHub repositories</li>
<li>For which GitHub repository would you like to set up a GitHub workflow? (format: user/repository)<br><strong>[your_github_username]/[your_github_repository_name]</strong></li>
<li>Set up the workflow to run a build script before every deploy?<br><strong>Yes</strong></li>
<li>What script should be run before every deploy? <br><strong>dotnet publish -c Release -o release src/BlazorWasmSample.csproj</strong></li>
<li>Set up automatic deployment to your site's live channel when a PR is merged?<strong><br>Yes<br></strong><em>This GitHub Actions workflow will run for every pull request made on your GitHub repository. The Firebase actions will create a new preview channel where the static app will be hosted at a subdomain unique for the PR.</em></li>
<li>What is the name of the GitHub branch associated with your site's live channel? <br><strong>main<br></strong><em>Or master if you still use the old default branch name.</em></li>
</ul>
<p> If you provided all of these answers to the prompts to <code>firebase init</code>, you will have</p>
<ul>
<li>created a Firebase project</li>
<li>enabled Firebase Hosting for the project</li>
<li>generated Firebase files like <em>.firebaserc</em> and <em>firebase.json</em> which holds some of the Firebase configuration necessary to deploy and host your application</li>
<li>generated a <em>.gitignore</em> file to ignore common files that need no tracking in Firebase projects</li>
<li>generated GitHub Actions workflows at the folder: <em>.github\workflows</em></li>
<li>Firebase added a secret to your GitHub repository secrets. This secret is used to authenticate to Firebase so the Firebase GitHub Actions can deploy and create preview channels.</li>
</ul>
<p> Let's give the generated files a closer look.</p>
<p><em>.firebaserc</em>:</p>
<pre style="color:#000000;background:#ffffff;">{&#10;  <span style="color:#2a00ff; ">"</span><span style="color:#2a00ff; ">projects</span><span style="color:#2a00ff; ">"</span>: {&#10;    <span style="color:#2a00ff; ">"</span><span style="color:#2a00ff; ">default</span><span style="color:#2a00ff; ">"</span>: <span style="color:#2a00ff; ">"</span><span style="color:#2a00ff; ">[your-project-id]</span><span style="color:#2a00ff; ">"</span>&#10;  }&#10;}&#10;</pre>
<p>This file holds the Firebase project id which it uses to deploy to the correct project when using <code>firebase deploy</code>.</p>
<p><em>firebase.json</em>:</p>
<pre style="color:#000000;background:#ffffff;">{&#10;  <span style="color:#2a00ff; ">"</span><span style="color:#2a00ff; ">hosting</span><span style="color:#2a00ff; ">"</span>: {&#10;    <span style="color:#2a00ff; ">"</span><span style="color:#2a00ff; ">public</span><span style="color:#2a00ff; ">"</span>: <span style="color:#2a00ff; ">"</span><span style="color:#2a00ff; ">release/wwwroot</span><span style="color:#2a00ff; ">"</span>,&#10;    <span style="color:#2a00ff; ">"</span><span style="color:#2a00ff; ">ignore</span><span style="color:#2a00ff; ">"</span>: [&#10;      <span style="color:#2a00ff; ">"</span><span style="color:#2a00ff; ">firebase.json</span><span style="color:#2a00ff; ">"</span>,&#10;      <span style="color:#2a00ff; ">"</span><span style="color:#2a00ff; ">**/.*</span><span style="color:#2a00ff; ">"</span>,&#10;      <span style="color:#2a00ff; ">"</span><span style="color:#2a00ff; ">**/node_modules/**</span><span style="color:#2a00ff; ">"</span>&#10;    ],&#10;    <span style="color:#2a00ff; ">"</span><span style="color:#2a00ff; ">rewrites</span><span style="color:#2a00ff; ">"</span>: [&#10;      {&#10;        <span style="color:#2a00ff; ">"</span><span style="color:#2a00ff; ">source</span><span style="color:#2a00ff; ">"</span>: <span style="color:#2a00ff; ">"</span><span style="color:#2a00ff; ">**</span><span style="color:#2a00ff; ">"</span>,&#10;        <span style="color:#2a00ff; ">"</span><span style="color:#2a00ff; ">destination</span><span style="color:#2a00ff; ">"</span>: <span style="color:#2a00ff; ">"</span><span style="color:#2a00ff; ">/index.html</span><span style="color:#2a00ff; ">"</span>&#10;      }&#10;    ]&#10;  }&#10;}&#10;</pre>
<p>This file is used to hold some parameters which influence how the project will be deployed using <code>firebase deploy</code>.<br>The file is also deployed to Firebase to configure things like routing. Here's what the different properties do:</p>
<ul>
<li>hosting
<ul>
<li><strong>public</strong>: specifies the folder that will be uploaded to Firebase Hosting. This folder should hold all the static assets you want to host.</li>
<li><strong>ignore</strong>: this array holds patterns of files to explicitly not upload to Firebase Hosting.</li>
<li><strong>rewrites</strong>: this array configures different rewrites and redirects. For single page applications (SPA) like Blazor WASM, you need to rewrite HTTP request to all paths to <em>/index.html</em>. That is exactly what the pre-configured rewrite above does.</li>
</ul>
</li>
</ul>
<p>Let's review the GitHub Actions workflow files later.</p>
<h2 id="create-a-github-actions-workflow-2">Deploy to Firebase Hosting manually</h2>
<p>Now that you initialized the folder with Firebase, you can manually deploy the Blazor WASM application to Firebase Hosting. First you need to publish the Blazor WASM application to the <em>release</em> folder:</p>
<pre style="color:#000000;background:#ffffff;">dotnet <span style="color:#2a00ff; ">publish</span> -c <span style="color:#2a00ff; ">Release</span> -o <span style="color:#2a00ff; ">release</span> <span style="color:#2a00ff; ">src/BlazorWasmSample.csproj</span>&#10;</pre>
<p>You can test out the hosting locally using firebase's hosting simulator with the <code>firebase serve</code> command:</p>
<pre style="color:#000000;background:#ffffff;">firebase <span style="color:#2a00ff; ">serve</span> <span style="color:#2a00ff; ">--only</span> <span style="color:#2a00ff; ">hosting</span>&#10;<span style="color:#3f7f59; "># Output: </span>&#10;<span style="color:#3f7f59; "># i  hosting: Serving hosting files from: release/wwwroot</span>&#10;<span style="color:#3f7f59; "># +  hosting: Local server: </span><span style="color:#3f3fbf; ">http://localhost:5000</span>&#10;</pre>
<p>The files you need to upload to Firebase Hosting will be at <em>release/wwwroot</em>. This has already been specified in <em>firebase.json</em>, so all you need to do is run the <code>firebase deploy</code> command:</p>
<pre style="color:#000000;background:#ffffff;">firebase <span style="color:#2a00ff; ">deploy</span>&#10;<span style="color:#3f7f59; "># Output:</span>&#10;<span style="color:#3f7f59; ">#  === Deploying to 'blazor-wasm-sample2'...</span>&#10;<span style="color:#3f7f59; ">#  </span>&#10;<span style="color:#3f7f59; ">#  i  deploying hosting</span>&#10;<span style="color:#3f7f59; ">#  i  hosting[blazor-wasm-sample2]: beginning deploy...</span>&#10;<span style="color:#3f7f59; ">#  i  hosting[blazor-wasm-sample2]: found 177 files in release/wwwroot</span>&#10;<span style="color:#3f7f59; ">#  +  hosting[blazor-wasm-sample2]: file upload complete</span>&#10;<span style="color:#3f7f59; ">#  i  hosting[blazor-wasm-sample2]: finalizing version...</span>&#10;<span style="color:#3f7f59; ">#  +  hosting[blazor-wasm-sample2]: version finalized</span>&#10;<span style="color:#3f7f59; ">#  i  hosting[blazor-wasm-sample2]: releasing new version...</span>&#10;<span style="color:#3f7f59; ">#  +  hosting[blazor-wasm-sample2]: release complete</span>&#10;<span style="color:#3f7f59; ">#  </span>&#10;<span style="color:#3f7f59; ">#  +  Deploy complete!</span>&#10;<span style="color:#3f7f59; ">#  </span>&#10;<span style="color:#3f7f59; ">#  Project Console: </span><span style="color:#3f3fbf; ">https://console.firebase.google.com/project/blazor-wasm-sample2/overview</span>&#10;<span style="color:#3f7f59; ">#  Hosting URL: </span><span style="color:#3f3fbf; ">https://blazor-wasm-sample2.web.app</span>&#10;</pre>
<p>Your Blazor WASM application will now be hosted on Firebase Hosting and you can find the URL in the output of the command.</p>
<p>Since you publish the Blazor application to the <em>release</em> folder, you should also ignore that folder in git. Add the <em>release</em> folder to <em>.gitignore</em> manually or use this PowerShell command:</p>
<pre style="color:#000000;background:#ffffff;">Add-Content -Path <span style="color:#2a00ff; ">./.gitignore</span> -NoNewline -Value <span style="color:#2a00ff; ">"</span><span style="color:#2a00ff; ">$(</span><span style="color:#7f0055; font-weight:bold; ">[Environment]</span><span style="color:#2a00ff; ">::</span><span style="color:#2a00ff; ">NewLine</span><span style="color:#2a00ff; ">)</span><span style="color:#2a00ff; ">release</span><span style="color:#2a00ff; ">"</span>;&#10;</pre>
<h2 id="create-a-github-actions-workflow-3">Deploy using GitHub Actions Workflow</h2>
<p>Two GitHub Actions workflow files were created during the Firebase initialization. Let's look look at what they do:</p>
<p><em>firebase-hosting-merge.yml</em>:</p>
<pre style="color:#000000;background:#ffffff;"># This file was auto-generated by the Firebase CLI&#10;# <span style="color:#3f3fbf; ">https://github.com/firebase/firebase-tools</span>&#10;&#10;name: Deploy to Firebase Hosting on merge&#10;<span style="color:#2a00ff; ">'</span><span style="color:#2a00ff; ">on</span><span style="color:#2a00ff; ">'</span>:&#10;  push:&#10;    branches:&#10;      - main&#10;jobs:&#10;  build_and_deploy:&#10;    runs-on: ubuntu-latest&#10;    steps:&#10;      - uses: actions/checkout@v2&#10;      - run: dotnet publish -c Release -o release src/BlazorWasmSample.csproj&#10;      - uses: FirebaseExtended/action-hosting-deploy@v0&#10;        with:&#10;          repoToken: <span style="color:#2a00ff; ">'</span><span style="color:#2a00ff; ">${{ secrets.GITHUB_TOKEN }}</span><span style="color:#2a00ff; ">'</span>&#10;          firebaseServiceAccount: <span style="color:#2a00ff; ">'</span><span style="color:#2a00ff; ">${{ secrets.FIREBASE_SERVICE_ACCOUNT_BLAZOR_WASM_SAMPLE2 }}</span><span style="color:#2a00ff; ">'</span>&#10;          channelId: live&#10;          projectId: blazor-wasm-sample2&#10;        env:&#10;          FIREBASE_CLI_PREVIEWS: hostingchannels&#10;</pre>
<p>This workflow is executed whenever a commit is pushed to the 'main' branch. The single job called 'build_and_deploy' is run on an Ubuntu machine. This machine has some software pre-installed. Today the 'ubuntu-latest' image comes with the .NET 5 SDK pre-configured, but at the time you are reading this, the SDK version could be a newer version. You can use the <a rel="noopener" href="https://github.com/actions/setup-dotnet" target="_blank">'setup-dotnet' GitHub Action</a> to setup a different version of .NET, or to ensure the version of the SDK will be the version specified even when the 'ubuntu-latest' image is updated to use newer versions of .NET. </p>
<p>The job performs the following steps:</p>
<ul>
<li>Get all the code from the main branch of your GitHub repository</li>
<li>Run the <code>dotnet publish</code> command</li>
<li>Use Firebase's GitHub Action to deploy to Firebase Hosting</li>
</ul>
<p><em>firebase-hosting-pull-request.yml</em>:</p>
<pre style="color:#000000;background:#ffffff;"># This file was auto-generated by the Firebase CLI&#10;# <span style="color:#3f3fbf; ">https://github.com/firebase/firebase-tools</span>&#10;&#10;name: Deploy to Firebase Hosting on PR&#10;<span style="color:#2a00ff; ">'</span><span style="color:#2a00ff; ">on</span><span style="color:#2a00ff; ">'</span>: pull_request&#10;jobs:&#10;  build_and_preview:&#10;    runs-on: ubuntu-latest&#10;    steps:&#10;      - uses: actions/checkout@v2&#10;      - run: dotnet publish -c Release -o release src/BlazorWasmSample.csproj&#10;      - uses: FirebaseExtended/action-hosting-deploy@v0&#10;        with:&#10;          repoToken: <span style="color:#2a00ff; ">'</span><span style="color:#2a00ff; ">${{ secrets.GITHUB_TOKEN }}</span><span style="color:#2a00ff; ">'</span>&#10;          firebaseServiceAccount: <span style="color:#2a00ff; ">'</span><span style="color:#2a00ff; ">${{ secrets.FIREBASE_SERVICE_ACCOUNT_BLAZOR_WASM_SAMPLE2 }}</span><span style="color:#2a00ff; ">'</span>&#10;          projectId: blazor-wasm-sample2&#10;        env:&#10;          FIREBASE_CLI_PREVIEWS: hostingchannels&#10;</pre>
<p>This workflow is executed whenever a pull request is created on your GitHub repository. The workflow does mostly the same. The only difference is that there's no channelid specified in the Firebase deploy action. By not specifying the channelid, Firebase's GitHub action will create a unique preview channel for the PR and comment the details of the deploy in the PR conversation. The comment will look like the screenshot below:</p>
<picture>
  <img src="https://swimburger.net/cdn-cgi/image/format=auto,quality=90,width=1120/media/fuab32m3/firebase-github-action-pr-comment.png" srcset="https://swimburger.net/cdn-cgi/image/format=auto,quality=90,width=430/media/fuab32m3/firebase-github-action-pr-comment.png 430w, https://swimburger.net/cdn-cgi/image/format=auto,quality=90,width=645/media/fuab32m3/firebase-github-action-pr-comment.png 645w, https://swimburger.net/cdn-cgi/image/format=auto,quality=90,width=718/media/fuab32m3/firebase-github-action-pr-comment.png 718w, https://swimburger.net/cdn-cgi/image/format=auto,quality=90,width=860/media/fuab32m3/firebase-github-action-pr-comment.png 860w, https://swimburger.net/cdn-cgi/image/format=auto,quality=90,width=1077/media/fuab32m3/firebase-github-action-pr-comment.png 1077w, https://swimburger.net/cdn-cgi/image/format=auto,quality=90,width=1120/media/fuab32m3/firebase-github-action-pr-comment.png 1120w" sizes="(max-width: 480px) 430px, (max-width: 768px) 718px, 1120px" width="1120" height="285" alt="Screenshot of the comment left by Firebase's GitHub Action. The comment contains the URL to the new preview channel created on GitHub Hosting." loading="lazy" decoding="async">
</picture>
<p>Both workflow files use a secret containing the auth token to perform operations against Firebase. The name of the secret starts with 'FIREBASE_SERVICE_ACCOUNT_'. This secret was created during the Firebase initialization and can be found under the GitHub repository settings like you can see in the screenshot below:</p>
<picture>
  <img src="https://swimburger.net/cdn-cgi/image/format=auto,quality=90,width=1120/media/jcpnqd3g/github-com_swimburger_firebasehostingblazorwasm_settings_secrets_actions-ipad-pro.png" srcset="https://swimburger.net/cdn-cgi/image/format=auto,quality=90,width=430/media/jcpnqd3g/github-com_swimburger_firebasehostingblazorwasm_settings_secrets_actions-ipad-pro.png 430w, https://swimburger.net/cdn-cgi/image/format=auto,quality=90,width=645/media/jcpnqd3g/github-com_swimburger_firebasehostingblazorwasm_settings_secrets_actions-ipad-pro.png 645w, https://swimburger.net/cdn-cgi/image/format=auto,quality=90,width=718/media/jcpnqd3g/github-com_swimburger_firebasehostingblazorwasm_settings_secrets_actions-ipad-pro.png 718w, https://swimburger.net/cdn-cgi/image/format=auto,quality=90,width=860/media/jcpnqd3g/github-com_swimburger_firebasehostingblazorwasm_settings_secrets_actions-ipad-pro.png 860w, https://swimburger.net/cdn-cgi/image/format=auto,quality=90,width=1077/media/jcpnqd3g/github-com_swimburger_firebasehostingblazorwasm_settings_secrets_actions-ipad-pro.png 1077w, https://swimburger.net/cdn-cgi/image/format=auto,quality=90,width=1120/media/jcpnqd3g/github-com_swimburger_firebasehostingblazorwasm_settings_secrets_actions-ipad-pro.png 1120w, https://swimburger.net/cdn-cgi/image/format=auto,quality=90,width=1436/media/jcpnqd3g/github-com_swimburger_firebasehostingblazorwasm_settings_secrets_actions-ipad-pro.png 1436w, https://swimburger.net/cdn-cgi/image/format=auto,quality=90,width=1680/media/jcpnqd3g/github-com_swimburger_firebasehostingblazorwasm_settings_secrets_actions-ipad-pro.png 1680w, https://swimburger.net/cdn-cgi/image/format=auto,quality=90,width=2240/media/jcpnqd3g/github-com_swimburger_firebasehostingblazorwasm_settings_secrets_actions-ipad-pro.png 2240w" sizes="(max-width: 480px) 430px, (max-width: 768px) 718px, 1120px" width="1120" height="653" alt="Screenshot of the secrets settings on the GitHub repository after Firebase initialization. One repository secret can be seen." loading="lazy" decoding="async">
</picture>
<p>These files are only on your machine. You need to push them up to GitHub. Run the following commands to add the new files to git, commit them, and push them to GitHub:</p>
<pre style="color:#000000;background:#ffffff;"><span style="color:#3f7f59; "># track all files that are not ignore by .gitignore </span>&#10;git <span style="color:#2a00ff; ">add</span> <span style="color:#2a00ff; ">--all</span> &#10;<span style="color:#3f7f59; "># commit all changes to the repository</span>&#10;git <span style="color:#2a00ff; ">commit</span> -m <span style="color:#2a00ff; ">"</span><span style="color:#2a00ff; ">Add Firebase files</span><span style="color:#2a00ff; ">"</span>&#10;<span style="color:#3f7f59; "># push the commits to GitHub</span>&#10;git <span style="color:#2a00ff; ">push</span>&#10;</pre>
<p>Now the GitHub Action workflows will take effect. You can try out the automated build and deploys by modifying your Blazor project and pushing the changes to GitHub. Make sure to also try out the PR functionality!</p>
<h2 id="create-aspnet-core-blazor-webassembly-project-2">Summary</h2>
<p>Blazor WebAssembly can be served as static files. These files can be hosted in static hosting services such as Firebase Hosting. Using the Firebase CLI, you can create new Firebase projects and initialize the project on your local machine for deployment to Firebase Hosting. The initialization also can generate GitHub Actions workflow files to automate the build and deployment.</p>
