TechBuzzPro

Deploy .NET App Without Dockerfile or Docker Build

· 4 min read · Apps & Browsers

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

This guide shows how to deploy a .NET application to a server or cloud service without using a Dockerfile or the docker build process. Instead, you'll use the .NET SDK's built-in publish command to create a self-contained or framework-dependent deployment package, then transfer it to the target machine and run it directly. This approach is faster for simple deployments, avoids Docker overhead, and works in environments where Docker isn't available.

What You'll Need

  • A .NET application (any version, but the steps assume .NET 6 or later; adjust commands for older versions).
  • .NET SDK installed on your development machine (download from the official .NET site).
  • Access to the target server or machine (SSH, FTP, or a shared folder).
  • If deploying to a Linux server, ensure the target has the necessary runtime if you choose a framework-dependent deployment; for self-contained, no runtime is needed.

Step-by-Step

  1. Open a terminal in your project directory. Navigate to the folder containing your .csproj file.
  2. Choose a deployment mode. Decide between framework-dependent (requires .NET runtime on the server) or self-contained (includes runtime, larger but standalone). For simplicity, this guide uses self-contained for Linux, but you can adapt.
  3. Run the publish command. Execute the following in the terminal:
    dotnet publish -c Release -r linux-x64 --self-contained true -o ./publish
    Replace linux-x64 with your target runtime (e.g., win-x64, osx-x64). The -o specifies the output folder.
  4. Verify the output. Check the publish folder. It should contain your app's executable (e.g., MyApp on Linux, MyApp.exe on Windows) and all necessary DLLs.
  5. Transfer the publish folder to the target machine. Use SCP, FTP, rsync, or a shared drive. For example, on Linux:
    scp -r ./publish user@server:/var/www/myapp
    Ensure the destination folder exists and has appropriate permissions.
  6. Set up the application on the server. On Linux, make the executable executable:
    chmod +x /var/www/myapp/MyApp
    If you're using a framework-dependent deployment, install the .NET runtime on the server first (see FAQ).
  7. Run the application. Execute it directly:
    /var/www/myapp/MyApp
    For a web app, it will start listening on the configured port (e.g., 5000). To keep it running after you log out, use a process manager like systemd (create a service file) or nohup.
  8. Configure a reverse proxy (optional). For production web apps, set up Nginx or Apache to forward requests to your app's port. This is beyond this guide but recommended for security and performance.

Common Mistakes

  • Wrong runtime identifier: Publishing for the wrong OS/architecture (e.g., publishing for win-x64 but deploying to Linux) causes a "not a valid executable" error.
  • Forgetting to set permissions: On Linux, the executable bit must be set; otherwise, you get "Permission denied".
  • Framework-dependent without runtime: If you choose framework-dependent and the server lacks the .NET runtime, the app fails with a missing runtime error.
  • Not including all files: The publish folder must be transferred as a whole; missing DLLs cause runtime errors.
  • Port conflicts: The app's configured port (e.g., 5000) might be in use; check with netstat or ss.

Tips

  • Use --self-contained false if you want a smaller package and can install the runtime on the server.
  • For production, set the ASPNETCORE_ENVIRONMENT environment variable to Production to disable developer exception pages.
  • Consider using a publish profile (dotnet publish -p:PublishProfile=FolderProfile) for repeatable builds.
  • For web apps, configure Kestrel to listen on a specific port via appsettings.json or environment variables.
  • Test the published app locally before deploying to catch issues early.

Troubleshooting

  • App won't start: "No such file or directory" - This often means the executable bit is missing or the runtime identifier is wrong. Re-publish with the correct RID and set permissions.
  • App starts but immediately exits with an error - Check the logs. For framework-dependent apps, ensure the runtime is installed. For self-contained, the app should run without external dependencies.
  • Port already in use - Change the port in your app's configuration or stop the conflicting process.
  • Missing DLL errors - Ensure you transferred the entire publish folder, not just the executable.
  • Permission denied when running - Run chmod +x on the executable.
  • App runs but doesn't respond to requests - Check firewall rules and ensure the app is listening on the correct interface (e.g., 0.0.0.0 instead of localhost).

Frequently Asked Questions

Can I deploy without the SDK on the server?

Yes, if you publish a self-contained deployment, the server doesn't need the SDK or runtime. For framework-dependent, you need the .NET runtime installed.

What is the difference between self-contained and framework-dependent?

Self-contained includes the .NET runtime with your app, making it larger but independent. Framework-dependent requires the runtime to be installed on the server, resulting in a smaller package.

How do I install the .NET runtime on a Linux server?

Use the package manager (e.g., sudo apt install aspnetcore-runtime-8.0 for Ubuntu) or download the binary from the official .NET site.

Can I deploy to a Windows server using this method?

Yes, publish with -r win-x64 and transfer the folder to the Windows server. You may need to install the .NET runtime if framework-dependent.

How do I keep the app running after I close the terminal?

Use a process manager like systemd on Linux, or run it as a Windows service. For quick tests, use nohup.

Is it possible to publish for multiple platforms from one machine?

Yes, you can publish for different RIDs (e.g., linux-x64, win-x64) from the same machine, as long as you have the SDK installed.