Search code examples
c#.netrazorblazormaui

AddMauiBlazorWebViewDeveloperTools don't exist


In this microsoft documentation is recommended to use builder.Services.AddMauiBlazorWebViewDeveloperTools(); but when i use it my VS gives an error saying that this directive doesn't exist... I'm using builder.Services.AddBlazorWebViewDeveloperTools(); for now.

Does anyone know why I can't use this?

I tried to use this as indicated in the documentation, I looked for some solutions on the internet, but nothing very concrete


Solution

  • You can create a .NET MAUI Blazor app directly. It's the equivalent of adding BlazorWebView to an existing app, automating those steps. For example it contains the following code:

    public static class MauiProgram
    {
        public static MauiApp CreateMauiApp()
        {
            var builder = MauiApp.CreateBuilder();
            builder
                .UseMauiApp<App>()
                .ConfigureFonts(fonts =>
                {
                    fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
                });
    
            builder.Services.AddMauiBlazorWebView();
    #if DEBUG
            builder.Services.AddMauiBlazorWebViewDeveloperTools();
    #endif
            // Register any app services on the IServiceCollection object
            // e.g. builder.Services.AddSingleton<WeatherForecastService>();
    
            return builder.Build();
        }
    }
    

    You can try it. It will not report an error like this: "directive doesn't exist..."