6. Build, publish and deploy
Publishing the server project builds the React app and bundles it with the API into one deployable app.
Publish from the command line
dotnet publish ReactWithAspNet.Server -c Release -o ./publish
The client build output (dist, created by npm run build) is included under wwwroot in the publish folder. Check the folder to confirm index.html and the assets directory are present.
Run the published app locally
cd publish
dotnet ReactWithAspNet.Server.dll
Publish with Visual Studio
- Right-click the server project and choose Publish.
- Pick a target such as Azure → Azure App Service (Windows or Linux), or Folder.
- Choose or create the App Service, then select Publish.
Deploy to Azure App Service with the CLI
RG=rg-reactdemo
APP=app-reactdemo-12345 # must be globally unique
az group create --name $RG --location australiaeast
az appservice plan create --resource-group $RG --name plan-reactdemo --sku B1
az webapp create --resource-group $RG --plan plan-reactdemo --name $APP --runtime "dotnet:10"
cd publish
zip -r ../site.zip .
cd ..
az webapp deploy --resource-group $RG --name $APP --src-path site.zip --type zip
Runtime strings and supported versions change, so confirm the available runtimes with az webapp list-runtimes.
Production checklist
- Confirm
MapFallbackToFile("/index.html")is present so deep links like/todos/5reload correctly. - Serve everything over HTTPS and keep
UseHttpsRedirectionenabled. - Keep secrets out of the React bundle. Anything shipped to the browser is public. Keep secrets on the server.
- Use environment-specific settings (
appsettings.Production.json, App Service configuration) for the API. - Add health checks and Application Insights for monitoring.
- Set up CI with
npm ci,npm run lint,npm testanddotnet publish.
A simple CI outline (GitHub Actions)
name: build
on:
push:
branches: [ main ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 22
- uses: actions/setup-dotnet@v4
with:
dotnet-version: 10.0.x
- name: Test front end
working-directory: reactwithaspnet.client
run: |
npm ci
npm test --if-present
- name: Publish
run: dotnet publish ReactWithAspNet.Server -c Release -o publish