Nima Tahmasebi
Nima Tahmasebi

Reputation: 141

Deploy Next JS project with asp.net core visual studio react template

I decided to add ssr capability with nextjs to the project that started with asp.net core react template in visual studio. Before adding nextjs when I clicked on the run project button in visual studio both api server and cra server would've started without any problems...but after adding next to my project it gives me a server error.

I fixed that by running npm run dev or npm start in vs code to start nextjs server alongside visual studio.

And now that I want to publish my project in visual studio there is no clientApp or any other react related folder in my published folder ( and of course it gives internal server error when uploaded to server and looks like it doesn't even build my nextjs app )

How can I publish my nextjs app based on visual studio asp.net core react template?

Upvotes: 2

Views: 9353

Answers (2)

Gift Ntokozo Mavuso
Gift Ntokozo Mavuso

Reputation: 437

What worked for me was using the NextjsStaticHosting-AspNetCore Following the the steps below:

  1. Add the package using dotnet add package NextjsStaticHosting.AspNetCore --version 0.9.2-preview.

  2. Add Next.js hosting support: services.Configure<NextjsStaticHostingOptions(config.GetSection("NextjsStaticHosting")); services.AddNextjsStaticHosting();

  3. Add the following section on appsettings.json: "NextjsStaticHosting": {"RootPath": "client-app"}

  4. Add the following command on package.json "build:export": "npx next build && npx next export -o build/"

  5. Update your build command on your .csproj file to the following:

    <Exec WorkingDirectory="$(SpaRoot)" Command="npm run build:export" />

Upvotes: 0

Related Questions