Why Deploying C# is Not Scary, But Profitable
\n\nImagine: you've written a cool C# application — be it a Telegram bot on .NET 8, a web API for an online store, or a microservice for processing payments. The code is debugged, tests pass, everything runs smoothly locally. There's only one last step left — to put it online so real people can use it.
\n\nAnd here's where the fun begins. Where to deploy? On a VPS, in Docker containers, or straight to the cloud? Each option has its pros, cons, and pitfalls. In this article, we'll break down all three approaches using real C# code examples so you can make an informed decision.
\n\nOption 1: VPS — The Classic for Those Who Love Total Control
\n\nA Virtual Private Server (VPS) is like renting an apartment in a "digital house." You have root access, you install the OS yourself, configure the firewall, and install the .NET Runtime. Ideal for those who want full control or have specific requirements.
\n\nHow to Deploy C# on a VPS: Step by Step
\n\nLet's say you have an ASP.NET Core Web API. Here's the minimum set of actions:
\n\n- \n
- Connect via SSH to the server (Ubuntu 22.04). \n
- Install the .NET Runtime: \n
wget https://dotnet.microsoft.com/download/dotnet/scripts/v1/dotnet-install.sh\nchmod +x dotnet-install.sh\n./dotnet-install.sh --channel 8.0\nexport PATH="$HOME/.dotnet:$PATH"\n\nBuild the application in Release mode and copy the files to the server via SCP or Rsync:
\n\ndotnet publish -c Release -o ./publish\nscp -r ./publish/* user@your-server:/var/www/myapp/\n\nRun the application as a systemd service so it automatically restarts after crashes:
\n\n[Unit]\nDescription=My C# App\n\n[Service]\nWorkingDirectory=/var/www/myapp\nExecStart=/home/user/.dotnet/dotnet /var/www/myapp/MyApp.dll\nRestart=always\nRestartSec=10\n\n[Install]\nWantedBy=multi-user.target\n\nPros of VPS: full control, low price (from $5/month), you can run anything — Windows or Linux.
\n\nCons: you are responsible for security, updates, and backups. If the application crashes at 3 AM — you're the one getting up.
\n\nOption 2: Docker — Containerization for Lazy Perfectionists
\n\nDocker is a way to package your C# application with all its dependencies into a lightweight container. "It works on my machine" turns into "it works everywhere."
\n\nDockerfile for .NET 8
\n\nCreate a Dockerfile in the project root:
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build\nWORKDIR /app\nCOPY *.csproj .\nRUN dotnet restore\nCOPY . .\nRUN dotnet publish -c Release -o out\n\nFROM mcr.microsoft.com/dotnet/aspnet:8.0 AS runtime\nWORKDIR /app\nCOPY --from=build /app/out .\nENV ASPNETCORE_URLS=http://+:80\nEXPOSE 80\nENTRYPOINT ["dotnet", "MyApp.dll"]\n\nBuild and run:
\n\ndocker build -t my-csharp-app .\ndocker run -d -p 8080:80 --name myapp my-csharp-app\n\nNow your application is available at http://localhost:8080. If you need multiple services (database + API + frontend), use Docker Compose:
version: '3.8'\nservices:\n api:\n build: .\n ports:\n - "5000:80"\n depends_on:\n - db\n db:\n image: postgres:15\n environment:\n POSTGRES_PASSWORD: example\n\nPros of Docker: isolation, reproducibility, easy scaling (just run 5 more containers), environment consistency.
\n\nCons: you need to understand Docker networks and volumes; it can be overkill for a simple application.
\n\nOption 3: Cloud — Delegate Infrastructure to the Professionals
\n\nCloud platforms (Microsoft Azure, AWS, Google Cloud, as well as Russian equivalents — Yandex Cloud, VK Cloud) take over server management, load balancing,