Deployment in Blazor

17 Nov 20232 minutes to read

This section provides information about deploying Blazor applications with the Syncfusion Blazor components.

Refer to Host and deploy ASP.NET Core Blazor topic for more information.

Publish Blazor Application with Visual Studio

  • Right-click on the project in the Solution Explorer and select Publish.

Solution Explorer in Blazor

  • Then, select the Folder option and select the publishing target location.

Publish Location in Blazor

  • Check the configuration as Release by clicking the Advanced... option below the target location.

Release Configuration in Blazor

  • For Blazor Server side application, set Deployment Mode as Self-Contained. Because some dependencies are not loaded properly when the published folder is hosted.

Deploy Mode in Blazor

  • Then, click Save and Publish.

    NOTE

    Refer here for publishing the application to Azure App Service using Visual Studio.

Publish Blazor Application with CLI

Packing the application and its dependencies into a folder for deployment to a hosting system by using the dotnet publish command.

For CLI deployment, run the following command from your root directory.

dotnet publish -c Release

For Blazor Server CLI deployment.

dotnet publish -c Release --self-contained true -r win-x86

Refer to the dotnet publish - arguments to learn about various optional arguments. Use the following command to specify the path for the output directory.

dotnet publish -c Release -o <output directory>

NOTE

If the output directory is not specified, it defaults to ./bin/[configuration]/[framework]/publish/ for a framework-dependent deployment and ./bin/[configuration]/[framework]/[runtime]/publish/ for a self-contained deployment.

If the path is relative, the output directory generated is relative to the project file location, not to the current working directory. Now, the published folder can be hosted in IIS or Azure app service.

Ahead-of-time (AOT) compilation in Blazor WebAssembly

Blazor WebAssembly supports ahead-of-time (AOT) compilation which provides improved runtime performance at the expense of a larger app size. Refer to Ahead-of-time (AOT) compilation topic to learn more about how it works and how to enable.

Enable AOT in the application

To enable AOT compilation in the application, add RunAOTCompilation options with value to true in the Blazor WebAssembly app’s project file.

<PropertyGroup>
    <RunAOTCompilation>true</RunAOTCompilation>
</PropertyGroup>

See also