> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify.com/RicardoAlejandroSantillan/dev-showcase/llms.txt
> Use this file to discover all available pages before exploring further.

# Building for Production

> Learn how to build and publish the Dev Showcase portfolio for production deployment

## 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:

<CardGroup cols={2}>
  <Card title=".NET 9.0 SDK" icon="download">
    Required to build and publish the application
  </Card>

  <Card title="Source Code" icon="code">
    Complete project with all dependencies restored
  </Card>
</CardGroup>

## Build Process

<Steps>
  <Step title="Clean Previous Builds">
    Remove any previous build artifacts to ensure a clean build:

    ```bash theme={null}
    dotnet clean
    ```

    Expected output:

    ```plaintext theme={null}
    Build succeeded.
        0 Warning(s)
        0 Error(s)
    ```
  </Step>

  <Step title="Restore Dependencies">
    Restore NuGet packages and dependencies:

    ```bash theme={null}
    dotnet restore
    ```

    This reads the project file and downloads required packages.
  </Step>

  <Step title="Build in Release Mode">
    Build the application with Release configuration:

    ```bash theme={null}
    dotnet build --configuration Release
    ```

    Expected output:

    ```plaintext theme={null}
    Build succeeded.
        0 Warning(s)
        0 Error(s)

    Time Elapsed 00:00:05.23
    ```

    <Note>
      Release mode enables optimizations, removes debug symbols, and prepares the application for production performance.
    </Note>
  </Step>

  <Step title="Publish the Application">
    Create a self-contained deployment package:

    ```bash theme={null}
    dotnet publish --configuration Release --output ./publish
    ```

    This creates a production-ready package in the `./publish` directory.
  </Step>
</Steps>

## Build Configurations

The Dev Showcase project supports two build configurations:

<Tabs>
  <Tab title="Debug">
    Used for development with debugging symbols:

    ```bash theme={null}
    dotnet build --configuration Debug
    ```

    **Features**:

    * Debug symbols included
    * Detailed error messages
    * Exception handler disabled
    * Hot reload support
  </Tab>

  <Tab title="Release">
    Optimized for production deployment:

    ```bash theme={null}
    dotnet build --configuration Release
    ```

    **Features**:

    * Code optimization enabled
    * Debug symbols removed
    * Exception handler enabled
    * Smaller binary size
  </Tab>
</Tabs>

## Static Asset Handling

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

### MapStaticAssets

From `Program.cs:14`:

```csharp theme={null}
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

```plaintext theme={null}
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
```

<Info>
  Static assets are served from the `wwwroot` directory and are automatically included in the publish output.
</Info>

## Environment Configuration

The application uses different settings based on the environment.

### appsettings.json

Production configuration from `appsettings.json:1-9`:

```json theme={null}
{
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft.AspNetCore": "Warning"
    }
  },
  "AllowedHosts": "*"
}
```

### appsettings.Development.json

Development-specific settings from `appsettings.Development.json:1-8`:

```json theme={null}
{
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft.AspNetCore": "Warning"
    }
  }
}
```

<Note>
  Environment-specific settings automatically override base settings. The application detects the environment using the `ASPNETCORE_ENVIRONMENT` variable.
</Note>

## Output Optimization

### Project Configuration

From `dev-showcase.csproj:1-9`:

```xml theme={null}
<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:

```bash theme={null}
# 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
```

<Warning>
  Be cautious with trimming. It may remove assemblies used through reflection. Test thoroughly when using `PublishTrimmed`.
</Warning>

## Production Checklist

Before deploying to production, verify:

<AccordionGroup>
  <Accordion title="Environment Settings">
    * [ ] `ASPNETCORE_ENVIRONMENT` set to "Production"
    * [ ] Logging configured appropriately
    * [ ] Exception handler enabled
    * [ ] HSTS configured
  </Accordion>

  <Accordion title="Static Assets">
    * [ ] All CSS files included
    * [ ] JavaScript modules present
    * [ ] Language JSON files (en.json, es.json)
    * [ ] Images and icons
    * [ ] Downloadable CV files
    * [ ] Favicon included
  </Accordion>

  <Accordion title="Security">
    * [ ] HTTPS redirection enabled
    * [ ] Content Security Policy configured
    * [ ] Sensitive data removed from configuration
    * [ ] AllowedHosts configured appropriately
  </Accordion>

  <Accordion title="Performance">
    * [ ] Static asset compression enabled
    * [ ] Response caching configured
    * [ ] Output caching enabled where appropriate
    * [ ] CDN configured for static assets (optional)
  </Accordion>
</AccordionGroup>

## Troubleshooting

<Accordion title="Build fails with missing dependencies">
  Run `dotnet restore` to ensure all NuGet packages are installed:

  ```bash theme={null}
  dotnet restore
  dotnet build
  ```
</Accordion>

<Accordion title="Static files missing in publish output">
  Verify that files are in the `wwwroot` directory and check the `.csproj` file for any exclusions.
</Accordion>

<Accordion title="Incorrect environment detected">
  Set the environment explicitly:

  ```bash theme={null}
  export ASPNETCORE_ENVIRONMENT=Production
  dotnet run
  ```
</Accordion>

## Next Steps

<Card title="Hosting Your Portfolio" icon="server" href="/deployment/hosting">
  Learn about hosting options and deployment strategies
</Card>
