How to Publish a .NET MAUI Blazor App as Self-contained

c# and Microsoft .Net logo

Publishing a .NET MAUI Blazor app without requiring users to manually install the .NET Desktop Runtime involves creating a self-contained deployment. This type of deployment packages the application and the specific .NET runtime it requires into a single unit. Here’s how you can publish your application this way:

Steps to Publish a .NET MAUI Blazor App as Self-contained

  1. Prepare Your Project:

    • Make sure your .NET MAUI Blazor project is ready for release. This typically involves setting the Configuration to Release instead of Debug to ensure optimization.
  2. Use the .NET CLI to Publish:

    • Open a terminal or command prompt.
    • Navigate to the directory containing your project file (.csproj).
    • Use the dotnet publish command with parameters specifying a self-contained deployment and the target Runtime Identifier (RID).

    Here’s an example command:

    dotnet publish -c Release -f net7.0-windows10.0.19041.0 -r win-x64 --self-contained true /p:Platform=x86 /p:RuntimeIdentifier=win-x64
    

    Adjust the framework version (net7.0-windows10.0.19041.0), platform (x86), and Runtime Identifier (win-x64) to match your project setup and target platform.

  3. Choose the Correct Runtime Identifier (RID):

    • The RID specifies the target platform architecture. Examples include:
      • win-x86 for 32-bit Windows
      • win-x64 for 64-bit Windows
      • osx-x64 for macOS
      • linux-x64 for Linux

    You can find a list of RIDs here in the Microsoft documentation.

  4. Result of Publishing:

    • The publish command will create a publish folder within your project’s output directory (by default, this is under bin\Release\net7.0-windows10.0.19041.0\<target-RID>\publish).
    • This folder contains everything needed to run the app on the target machine, with no additional installations required.
  5. Distribution:

    • You can distribute your application by sharing the contents of the publish folder. Users can run the application by executing the main .exe file within this folder.

Considerations:

  • Application Size: Self-contained deployments can be significantly larger because they include the .NET runtime.

  • Updates to .NET Runtime: Since the app uses the bundled .NET runtime, it won’t benefit from updates to the runtime unless you publish and distribute a new version with the updated runtime.

  • Library Dependencies: Ensure that your app includes all necessary third-party DLLs and that there are no issues with native dependencies.

Following these steps should allow you to deploy your .NET MAUI Blazor app in a way that doesn’t require end-users to separately install the .NET Desktop Runtime.