Azure Static Web Apps is a service that automatically builds and deploys full stack web apps from a GitHub repository. Azure Static Web Apps consist of a static web frontend, and an Azure Functions based backend. When you create a Static Web Apps resource, Azure sets up a GitHub Actions workflow in the app’s source code repository that monitors a branch of your choice. Every time you push commits to the watched branch, the GitHub Action automatically builds and deploys your app and its API.
As of today, Azure Static Web Apps now has first-class support for Blazor WebAssembly and .NET Functions in preview, available in all supported regions. This was one of the top user requests since Static Web Apps was announced at Build. You can develop and deploy a frontend and a serverless API written entirely in .NET.
Let’s give it a try!
Getting Started
To help you get started, we’ve created a GitHub repository template, which you can use as a starting point for your own projects.
In GitHub, click on the Use this template button to create a new GitHub repository using the template, providing it a name of your choosing (we’ll use my-blazor-app here) and click Create repository from template.
There are three folders in the template:
- Client: The Blazor WebAssembly sample application
- API: A C# Azure Functions API, which the Blazor application will call
- Shared: A C# class library with a shared data model between the Blazor and Functions application
To run the app locally, start both the API and Client projects. The “Fetch data” page in the Blazor app requests weather forecast data form the backend Function API and display it on the page.
To run the app from the command-line, you’ll need to install the Azure Functions Core Tools for your platform of choice.
Deploying to Static Web Apps
To deploy this app as an Azure Static Web App, log into your Azure account (sign up for a free one here) and search for Static Web Apps.
Click Create, provide a Subscription, Resource Group and name for the application.
Next, sign into GitHub and locate your GitHub repo (my-blazor-app) and select the branch you wish to deploy.
Finally, select Blazor from the Build Presets, which will populate the App location, API location and App artifact location with Client, API and wwwroot. The first and second values are the path within the Git repository to where the project files for the Blazor and Functions app resides, so if you’ve modified the structure of the Git repository, make sure these values are updated to reflect. The third value is the output path that Blazor will compile into and doesn’t need updating.
Complete the wizard and Static Web Apps will create the GitHub Actions workflow file for you and deploy your application to Azure.
Summary
We started by forking a GitHub repository (but you could’ve also used a project created in Visual Studio/Visual Studio Code/etc.), created a Static Web App in Azure, and it setup a GitHub Actions workflow for us, automatically building and deploying our Blazor and Functions application. We’ve now got a statically hosted application with a serverless backend, ready to scale for our demands.
Additional Resources
To learn more about Blazor WebAssembly and .NET Functions on Static Web Apps, check out the quickstart docs, the Microsoft Learn module, as well as the comprehensive Static Web Apps docs.
Give Feedback
We’re excited to have Blazor WebAssembly and .NET Functions supported by Azure Static Web Apps, and can’t wait to see what you build with them. Let us know what you think by filing an issue on GitHub.
Thanks… works nicely.
Where are the compiled files stored? i created a .gitignore and removed bin and obj. Trying to understand where the compiled files will be located
Hi Team,
Happy Friday!
Quick question: Does Azure Static Web Apps support to install a certificate for a custom domain ? Let’s say I have a custom domain http://www.mydomain1.com, and I want to install an SSL certificate to access the Static Web App at https://www.mydomain1.com. Is that possible ? Thank you!
Hi Team,
Nevermind. I found out that I can use Azure Content Delivery Network (CDN) to accomplish this goal.
Thank you though!
Do we have an issue tagged for adding function monitoring and diagnostics. There’s really not much there and it makes it very hard to tell why things aren’t working.
You can link up with App Insights to monitor the API from a Static Web App, see https://www.aaron-powell.com/posts/2020-08-12-getting-logs-from-static-web-apps-apis/
Will there be Azure Devops integration, or just Github?
In the preview of Azure Static Web Apps only GitHub Actions is supported. You can track the status via the backlog issue on GitHub: https://github.com/Azure/static-web-apps/issues/5
Can someone please give sample how to use Microsoft DevOps instead of Github, please.
In the preview of Azure Static Web Apps only GitHub Actions is supported. You can track the status via the backlog issue on GitHub: https://github.com/Azure/static-web-apps/issues/5
as of my today experience publishing from Visual Studio doenst work for 5 RC1
Dialog pops up 3.18 max or self hosted.
To use Azure functions as our Web API backend on Azure, how do we then connect and use Azure PosgreSQL via and ORM like EF.Net core?
I hope you’re not suggesting to go back to old ADO.Net to write SQL statements in Azure functions?
Hi Ben. Great question! You can use Entity Framework Core from Azure Functions. Azure Functions supports dependency injection, like we do in ASP.NET Core, so you can configure your DbContext there: https://docs.microsoft.com/azure/azure-functions/functions-dotnet-dependency-injection.
Oh wow, I didn’t know that…
Thank you Dan for answering my question
You can use Entity Framework Core with Azure Functions, as described by Jeff Hollan in this article: https://dev.to/azure/using-entity-framework-with-azure-functions-50aa
You can find the PostgreSQL driver for EF Core documentation in the Npgsql website: https://www.npgsql.org/efcore/index.html, as far as I can see it behaves in the same way as the SQL Server driver for EF Core, so it should work with Azure Database for PostgreSQL, as mentioned in the Microsoft docs: https://docs.microsoft.com/en-us/dotnet/api/overview/azure/postgresql?view=azure-dotnet