Skip to main content
A newer version of this page is available. .

Microsoft Templates (NuGet Packages)

  • 5 minutes to read

Important

Ensure your system meets these requirements.

This topic describes how to:

Note

These instructions are also available in the following videos:

1. Create a New Project

The steps below describe how to create a new Blazor project. If you want to add DevExpress Blazor components to an existing application, go to Step 2.

  1. Click Create a new project on Visual Studio’s start page, select the Blazor Server App or Blazor WebAssembly App template, and click Next.

    Getting Started - Create a New Project

  2. Specify the project name and location, and click Next.

    Getting Started - Configure a New Project

  3. Specify additional options, and click Create.

2. Obtain You NuGet Feed Credentials

You need to obtain your personal NuGet feed credentials to access the DevExpress.Blazor NuGet package from your project. You can use NuGet feed URL or feed authorization key to manage DevExpress packages.

  1. Make sure your DevExpress.com account has access to Blazor UI Components. This product line is included in the Universal, DXperience, and ASP.NET subscriptions. Refer to the subscription comparison matrix for more information.

  2. Use your DevExpress credentials to log into nuget.devexpress.com.

  3. Obtain your NuGet feed credentials and copy them to the clipboard.

    NuGet Feed

    You can find the same URL in the Download Manager.

3. Install the DevExpress Blazor NuGet Package

  1. In Visual Studio, select ToolsNuGet Package ManagerPackage Manager Settings.

    GettingStarted Package Manager Settings

  2. Navigate to NuGet Package ManagerPackage Sources. Click the plus sign at the top right corner to add a new NuGet package source. Use the following package settings:

    • Name: DevExpress

    • Source: DevExpress NuGet Gallery (https://nuget.devexpress.com/api) if you use the feed key to authenticate. Otherwise, use the NuGet Feed URL (https://nuget.devexpress.com/{your feed authorization key}/api)

    Click OK.

    GettingStarted NuGet Feed API

    Note

    Make sure the nuget.org package source is also enabled.

  3. Select ToolsNuGet Package ManagerManage NuGet Packages for Solution.

    If you registered the DevExpress NuGet feed with an authorization key, the login form is displayed when you invoke the NuGet Package Manager window for the first time. Enter your credentials as follows:

    In the invoked dialog, open the Browse tab, and install the DevExpress.Blazor NuGet package.

    GettingStarted Install Package

  4. Build the project.

Refer to the following topic for more information: Setup Visual Studio's NuGet Package Manager.

4. Register DevExpress Resources

Blazor Server in .NET 6.0

  1. In the Pages/_Layout.cshtml file, add the following line to the end of the HEAD section:

    <head>
        @* ... *@
        <link href="_content/DevExpress.Blazor/dx-blazor.bs5.css" rel="stylesheet" />
    </head>
    
  2. Register the DevExpress.Blazor namespace in the _Imports.razor file:

    @using DevExpress.Blazor
    
  3. Call the AddDevExpressBlazor method in the Program.cs file.

    builder.Services.AddDevExpressBlazor();
    
  4. (Optional) Apply a DevExpress Bootstrap theme. We use the DevExpress Blazing Berry theme in our demos and documentation.

Blazor Server in .NET 5.0

  1. In the Pages/_Host.cshtml file, add the following line to the end of the HEAD section:

    <head>
        @* ... *@
        <link href="_content/DevExpress.Blazor/dx-blazor.css" rel="stylesheet" />
    </head>
    
  2. Register the DevExpress.Blazor namespace in the _Imports.razor file:

    @using DevExpress.Blazor
    
  3. Call the UseStaticWebAssets method on the host builder in the Program.cs file to enable the application to load client-side resources.

    public class Program {
        // ...
    
        public static IHostBuilder CreateHostBuilder(string[] args) =>
            Host.CreateDefaultBuilder(args)
                .ConfigureWebHostDefaults(webBuilder => {
                    webBuilder.UseStartup<Startup>();
                    webBuilder.UseStaticWebAssets();
                });
    }
    

    Refer to the following topics for more information: Consume content from a referenced RCL and Troubleshooting: Failed to load resource.

  4. (Optional) Apply a DevExpress Bootstrap theme. We use the DevExpress Blazing Berry theme in our demos and documentation.

  5. (Optional) Configure the project to use Bootstrap v5. Refer to the BootstrapVersion property description for more information.

Blazor WebAssembly in .NET 6.0

  1. Add the following line to the wwwroot/index.html file’s HEAD section:

    <head>
        @* ... *@
        <link href="_content/DevExpress.Blazor/dx-blazor.bs5.css" rel="stylesheet" />
    </head>
    
  2. Register the DevExpress.Blazor namespace in the _Imports.razor file:

    @using DevExpress.Blazor
    
  3. Call the AddDevExpressBlazor method in the Program.cs file.

    builder.Services.AddDevExpressBlazor();
    
  4. (Optional) Apply a DevExpress Bootstrap theme. We use the DevExpress Blazing Berry theme in our demos and documentation.

Note

If you enabled the ASP.NET Core hosted option when you create the project, make sure that the server-side project is set as the solution’s startup project.

Blazor WebAssembly in .NET 5.0

  1. Add the following line to the wwwroot/index.html file’s HEAD section:

    <head>
        @* ... *@
        <link href="_content/DevExpress.Blazor/dx-blazor.css" rel="stylesheet" />
    </head>
    
  2. Register the DevExpress.Blazor namespace in the _Imports.razor file:

    @using DevExpress.Blazor
    
  3. Call the AddDevExpressBlazor(IServiceCollection, Action<GlobalOptions>) method from your project’s Program.Main() method:

    using Microsoft.Extensions.DependencyInjection;
    
    public class Program {
        public static async Task Main(string[] args) {
            var builder = WebAssemblyHostBuilder.CreateDefault(args);
            // ...
            builder.Services.AddDevExpressBlazor();
            await builder.Build().RunAsync();
        }
    }
    
  4. (Optional) Apply a DevExpress Bootstrap theme. We use the DevExpress Blazing Berry theme in our demos and documentation.

  5. (Optional) Configure the project to use Bootstrap v5. Refer to the BootstrapVersion property description for more information.

Note

If you enabled the ASP.NET Core hosted option when you create the project, make sure that the server-side project is set as the solution’s startup project.

5. Add DevExpress Blazor Components

For instructions on how to add an individual DevExpress Blazor component to your application, refer to the documents below: