Skip to content

Deploy CMS PaaS

⏱ 20 minutes intermediate

Optimizely cloud hosting provides managed infrastructure for CMS PaaS — automatic scaling, database management, CDN, and environment promotion. Deploying to this environment frees you from managing servers and lets you focus on building your site.

  1. Prepare your project for deployment
  2. Create a deployment package
  3. Deploy using the Optimizely CLI or CI/CD pipeline
  4. Verify the deployment in each environment

Before deploying, ensure your project builds cleanly and has the correct configuration.

Verify build and configuration
bash
# Clean and build in Release mode
dotnet clean
dotnet build --configuration Release

# Run tests before deploying
dotnet test --configuration Release

# Verify the publish output
dotnet publish --configuration Release --output ./publish

Check your appsettings.json to ensure environment-specific settings use environment variables or the Optimizely configuration service.

Environment-aware configuration
csharp
var builder = WebApplication.CreateBuilder(args);

// Load environment-specific settings
builder.Configuration
    .AddJsonFile("appsettings.json", optional: false)
    .AddJsonFile(
        $"appsettings.{builder.Environment.EnvironmentName}.json",
        optional: true)
    .AddEnvironmentVariables();

builder.Services.AddCms();

Do not hardcode connection strings or secrets. Use environment variables that the Optimizely cloud injects at runtime.

The Optimizely cloud accepts NuGet packages (.nupkg) for deployment.

Create a NuGet deployment package
xml
<PropertyGroup>
    <TargetFramework>net8.0</TargetFramework>
    <PackageId>MySite.Cms</PackageId>
    <Version>1.0.0</Version>
    <EnableDefaultContentItems>true</EnableDefaultContentItems>
</PropertyGroup>

<ItemGroup>
    <Content Include="Views\**" />
    <Content Include="ClientResources\**" />
    <Content Include="wwwroot\**" />
</ItemGroup>
Pack the project
bash
# Create the deployment package
dotnet publish --configuration Release
nuget pack MySite.Cms.nuspec -Version 1.0.0 -OutputDirectory ./artifacts

The Optimizely CLI streamlines package uploads and environment promotion.

Deploy using the CLI
bash
# Install the Optimizely deployment CLI
dotnet tool install -g Optimizely.Cms.Cli

# Upload package to Integration environment
opti deploy upload \
    --project-id your-project-id \
    --api-key your-api-key \
    --api-secret your-api-secret \
    --package ./artifacts/MySite.Cms.1.0.0.nupkg \
    --target-environment Integration

# Check deployment status
opti deploy status \
    --project-id your-project-id \
    --api-key your-api-key \
    --api-secret your-api-secret

Set up a GitHub Actions workflow to deploy on every push to your release branch.

GitHub Actions deployment workflow
yaml
name: Deploy CMS
on:
  push:
    branches: [release]

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: Setup .NET
        uses: actions/setup-dotnet@v4
        with:
          dotnet-version: 8.0.x

      - name: Build and publish
        run: dotnet publish -c Release -o ./publish

      - name: Deploy to Integration
        run: |
          dotnet tool install -g Optimizely.Cms.Cli
          opti deploy upload \
            --project-id ${{ secrets.OPTI_PROJECT_ID }} \
            --api-key ${{ secrets.OPTI_API_KEY }} \
            --api-secret ${{ secrets.OPTI_API_SECRET }} \
            --package ./publish \
            --target-environment Integration

Optimizely cloud provides three environments: Integration, Preproduction, and Production. Promote code forward after testing.

Promote to Production
bash
# Promote from Integration to Preproduction
opti deploy promote \
    --project-id your-project-id \
    --source Integration \
    --target Preproduction

# After testing, promote to Production
opti deploy promote \
    --project-id your-project-id \
    --source Preproduction \
    --target Production

After each deployment:

  1. Check the deployment status in the Optimizely management portal
  2. Verify the site loads correctly in a browser
  3. Confirm content types synchronized — look for any migration warnings in logs
  4. Test critical user flows (content editing, publishing, search)
IssueCauseFix
Deployment times outPackage too large or slow networkExclude unnecessary files from the package
Missing views after deployViews not included in publish outputAdd <Content Include="Views\**" /> to .csproj
Database migration failsSchema conflictsReview migration logs and resolve conflicts before promoting