Skip to content

Deploying a .NET App

.NET is a modern, open-source development platform from Microsoft for building cross-platform web, cloud, desktop, and mobile applications. It features a powerful runtime, a rich ecosystem, and first-class support for C#, F#, and Visual Basic, making it ideal for scalable and high-performance solutions.

This guide explains how to deploy a .NET application to Klutch.sh, both with and without a Dockerfile. It also covers installation and provides sample code to get started.

Prerequisites

  • .NET 8 SDK (or your target version)
  • Git and GitHub account
  • Klutch.sh account

Getting Started: Install .NET & Create App

  1. Install the .NET SDK (Download here)
  2. Create a new .NET web app:
    Terminal window
    dotnet new web -n MyDotnetApp
    cd MyDotnetApp
  3. Run the development server:
    Terminal window
    dotnet run
    Your app should be running at http://localhost:5000 or http://localhost:8080.

Sample Code (Program.cs)

Add a simple endpoint to your .NET project:

var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();
app.MapGet("/", () => "Hello from .NET on Klutch.sh!");
var port = Environment.GetEnvironmentVariable("PORT") ?? "5000";
app.Urls.Add($"http://0.0.0.0:{port}");
app.Run();

Deploying Without a Dockerfile

  1. Push your .NET app to a GitHub repository.
  2. Log in to Klutch.sh.
  3. Create a new project and give it a name.
  4. Create a new app:
    • Select your .NET GitHub repository and branch
    • Set the port to route traffic (usually 5000 or 8080 for .NET)
    • Choose region, compute, number of instances, and add any environment variables
  5. Add a start command in your app settings:
    Terminal window
    dotnet run
  6. Click “Create” to deploy. Klutch.sh will build and deploy your app automatically.

Deploying With a Dockerfile

  1. Add a Dockerfile to your project root. Example:
    # Use official .NET image
    FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
    WORKDIR /app
    FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
    WORKDIR /src
    COPY . .
    RUN dotnet publish -c Release -o /app
    FROM base AS final
    WORKDIR /app
    COPY --from=build /app .
    # Expose port (match your .NET app)
    EXPOSE 5000
    EXPOSE 8080
    # Start the app
    ENV ASPNETCORE_URLS=http://0.0.0.0:$PORT
    ENTRYPOINT ["dotnet", "MyDotnetApp.dll"]
  2. Push your code (with Dockerfile) to GitHub.
  3. In Klutch.sh, follow the same steps to create a project and app, but select the Dockerfile option when prompted.
  4. Set the service details and environment variables as needed.
  5. Click “Create” to deploy. Klutch.sh will build your Docker image and deploy your app.

Note: Your .NET app should always listen on the PORT environment variable as shown above.


Resources


Deploying to Klutch.sh is simple and flexible. Choose the method that best fits your workflow and project requirements.