ASP.NET Core hosted React UI with Aspire

The template doesn’t work for me as-is. Here is how to fix it

  1. Create a new solution using the template React and ASP.NET Core.
  2. Make sure you check Enlist in Aspire.
  3. Add a project reference from the AppHost to the client project.
  4. Add a NuGet reference from AppHost to Aspire.Hosting.NodeJS.
  5. Edit AppHost.cs, delete builder.AddProject("reactapp10-server");
  6. And replace it with the following code:
var apiApp = builder.AddProject<Projects.ReactApp11_Server>("api");
var clientApp = builder.AddNpmApp("client", "../reactapp11.client", "dev")
    .WithReference(apiApp)
    .WaitFor(apiApp)
    .WithHttpsEndpoint(env: "DEV_SERVER_PORT")
    .WithExternalHttpEndpoints();

You can now run your AppHost project and see the React app listed, running, and with a valid URL exposed.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *