Skip to main content

Overview

Building the Dev Showcase portfolio for production involves compiling the ASP.NET Core application, optimizing static assets, and preparing the deployment package. This guide covers the complete build process from development to production-ready artifacts.

Prerequisites

Before building for production, ensure you have:

.NET 9.0 SDK

Required to build and publish the application

Source Code

Complete project with all dependencies restored

Build Process

1

Clean Previous Builds

Remove any previous build artifacts to ensure a clean build:
dotnet clean
Expected output:
Build succeeded.
    0 Warning(s)
    0 Error(s)
2

Restore Dependencies

Restore NuGet packages and dependencies:
dotnet restore
This reads the project file and downloads required packages.
3

Build in Release Mode

Build the application with Release configuration:
dotnet build --configuration Release
Expected output:
Build succeeded.
    0 Warning(s)
    0 Error(s)

Time Elapsed 00:00:05.23
Release mode enables optimizations, removes debug symbols, and prepares the application for production performance.
4

Publish the Application

Create a self-contained deployment package:
dotnet publish --configuration Release --output ./publish
This creates a production-ready package in the ./publish directory.

Build Configurations

The Dev Showcase project supports two build configurations:
Used for development with debugging symbols:
dotnet build --configuration Debug
Features:
  • Debug symbols included
  • Detailed error messages
  • Exception handler disabled
  • Hot reload support

Static Asset Handling

The Dev Showcase portfolio includes extensive static assets that are optimized during the build process.

MapStaticAssets

From Program.cs:14:
app.MapStaticAssets();
This configures static file serving with:
  • Content hashing: Files are versioned with content hashes
  • Cache headers: Optimized caching for performance
  • Compression: Gzip/Brotli compression enabled

Static Asset Structure

wwwroot/
├── css/              # Stylesheets (14 files)
│   ├── base.css
│   ├── layout.css
│   ├── responsive.css
│   └── ...
├── js/               # JavaScript modules
│   ├── main.js
│   ├── carousel.js
│   ├── charts-manager.js
│   └── ...
├── images/           # Images and graphics
├── languages/        # Translation files
│   ├── en.json
│   └── es.json
├── files/            # Downloadable CVs
└── lib/              # Third-party libraries
Static assets are served from the wwwroot directory and are automatically included in the publish output.

Environment Configuration

The application uses different settings based on the environment.

appsettings.json

Production configuration from appsettings.json:1-9:
{
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft.AspNetCore": "Warning"
    }
  },
  "AllowedHosts": "*"
}

appsettings.Development.json

Development-specific settings from appsettings.Development.json:1-8:
{
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft.AspNetCore": "Warning"
    }
  }
}
Environment-specific settings automatically override base settings. The application detects the environment using the ASPNETCORE_ENVIRONMENT variable.

Output Optimization

Project Configuration

From dev-showcase.csproj:1-9:
<Project Sdk="Microsoft.NET.Sdk.Web">
  <PropertyGroup>
    <TargetFramework>net9.0</TargetFramework>
    <Nullable>enable</Nullable>
    <ImplicitUsings>enable</ImplicitUsings>
  </PropertyGroup>
</Project>
Key settings:
  • TargetFramework: .NET 9.0 runtime
  • Nullable: Enables nullable reference types for safer code
  • ImplicitUsings: Reduces boilerplate with automatic using statements

Publish Options

Create optimized builds with additional options:
# Self-contained deployment (includes .NET runtime)
dotnet publish -c Release --self-contained true -r linux-x64

# Framework-dependent deployment (smaller, requires .NET installed)
dotnet publish -c Release --self-contained false

# Single file deployment
dotnet publish -c Release --self-contained true -r linux-x64 \
  -p:PublishSingleFile=true

# Trimmed deployment (smallest size)
dotnet publish -c Release --self-contained true -r linux-x64 \
  -p:PublishTrimmed=true
Be cautious with trimming. It may remove assemblies used through reflection. Test thoroughly when using PublishTrimmed.

Production Checklist

Before deploying to production, verify:
  • ASPNETCORE_ENVIRONMENT set to “Production”
  • Logging configured appropriately
  • Exception handler enabled
  • HSTS configured
  • All CSS files included
  • JavaScript modules present
  • Language JSON files (en.json, es.json)
  • Images and icons
  • Downloadable CV files
  • Favicon included
  • HTTPS redirection enabled
  • Content Security Policy configured
  • Sensitive data removed from configuration
  • AllowedHosts configured appropriately
  • Static asset compression enabled
  • Response caching configured
  • Output caching enabled where appropriate
  • CDN configured for static assets (optional)

Troubleshooting

Run dotnet restore to ensure all NuGet packages are installed:
dotnet restore
dotnet build
Verify that files are in the wwwroot directory and check the .csproj file for any exclusions.
Set the environment explicitly:
export ASPNETCORE_ENVIRONMENT=Production
dotnet run

Next Steps

Hosting Your Portfolio

Learn about hosting options and deployment strategies

Build docs developers (and LLMs) love