diff --git a/aspnetcore/blazor/components/render-components-outside-of-aspnetcore.md b/aspnetcore/blazor/components/render-components-outside-of-aspnetcore.md index b9021124b38f..e6bf3b2b92fa 100644 --- a/aspnetcore/blazor/components/render-components-outside-of-aspnetcore.md +++ b/aspnetcore/blazor/components/render-components-outside-of-aspnetcore.md @@ -16,17 +16,22 @@ uid: blazor/components/render-outside-of-aspnetcore In the following example, a Razor component is rendered to an HTML string from a console app: -In a command shell, create a new console app project: +In a command shell, create a new console app project and change the directory to the `ConsoleApp1` folder: ```dotnetcli dotnet new console -o ConsoleApp1 cd ConsoleApp1 ``` -In a command shell in the `ConsoleApp1` folder, add package references for and to the console app: +Add a package reference for : ```dotnetcli dotnet add package Microsoft.AspNetCore.Components.Web +``` + +Add a package reference for : + +```dotnetcli dotnet add package Microsoft.Extensions.Logging ``` @@ -48,17 +53,15 @@ Add the following `RenderMessage` component to the project. @code { [Parameter] - public string Message { get; set; } + public string? Message { get; set; } } ``` -Update the `Program` file: +Replace the code in the `Program` file with the following code: * Set up dependency injection (/) and logging (/). * Create an and render the `RenderMessage` component by calling . -Any calls to must be made in the context of calling `InvokeAsync` on a component dispatcher. A component dispatcher is available from the property. - ```csharp using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Components.Web; @@ -93,6 +96,8 @@ Console.WriteLine(html); > [!NOTE] > Pass to when rendering the component without passing parameters. +Any calls to must be made in the context of calling `InvokeAsync` on a component dispatcher. A component dispatcher is available from the property. + Alternatively, you can write the HTML to a by calling `output.WriteHtmlTo(textWriter)`. The task returned by completes when the component is fully rendered, including completing any asynchronous lifecycle methods. If you want to observe the rendered HTML earlier, call instead. Then, wait for the component rendering to complete by awaiting on the returned instance.