How to Deploy a .NET Application from Visual Studio to a Linux Server

Deploying a .NET application to a Linux server might sound challenging, especially if you’ve built and tested it entirely on Windows using Visual Studio. But with the cross-platform power of .NET Core and .NET 5+, deploying your app to Linux has never been easier. In this guide, we’ll walk through the exact steps to get your .NET app running on a Linux server — whether you’re managing a startup, building your own side project, or migrating workloads.


What You’ll Learn

  • What type of .NET application works on Linux
  • How to prepare your build in Visual Studio
  • How to publish your app for Linux deployment
  • What files to copy to the Linux server
  • How to run and optionally daemonize your app as a service

Step 1: Check Your .NET Version

The first and most important thing is understanding what type of .NET you’re using:

.NET VersionLinux Compatible?
.NET Framework (4.x)❌ No
.NET Core (3.x)✅ Yes
.NET 5, 6, 7, 8✅ Yes

If your app is built with .NET Core or .NET 5/6/7/8, you’re good to go!

✅ Tip: To check, open your .csproj file and look for the TargetFramework. Example:

<TargetFramework>net6.0</TargetFramework>

Step 2: Publish for Linux

Open Visual Studio and follow these steps:

  1. Go to Build > Publish.
  2. Choose a folder as the target.
  3. Click Edit next to “Configuration” and set:
    • Target Framework: .NET 6 (or the version you’re using)
    • Deployment Mode: Self-contained
    • Target Runtime: linux-x64
  4. Click Publish.

Alternatively, run this from the terminal (recommended for control):

dotnet publish -c Release -r linux-x64 --self-contained true

This creates a standalone Linux build, complete with a native executable and all needed dependencies.

🎯 SEO keywords: dotnet publish linux, deploy dotnet core to linux, dotnet self-contained linux, run dotnet app on ubuntu


Step 3: Copy Files to Linux Server

You can now copy the published output to your Linux server:

scp -r bin/Release/net6.0/linux-x64/publish/ user@yourserver:/opt/mydotnetapp

🔐 Tip: Make sure the Linux server has the right permissions and SSH access.


Step 4: Run the App on Linux

SSH into your server:

ssh user@yourserver
cd /opt/mydotnetapp
chmod +x MyAppExecutable
./MyAppExecutable

If it starts successfully, you’ve just run your Windows-built .NET app on Linux!


Step 5 (Optional): Run as a Linux Service

To run the app in the background or on boot, create a systemd service:

  1. Create a file: /etc/systemd/system/mydotnetapp.service
  2. Add the following:
[Unit]
Description=My .NET App
After=network.target

[Service]
WorkingDirectory=/opt/mydotnetapp
ExecStart=/opt/mydotnetapp/MyAppExecutable
Restart=always
RestartSec=10
SyslogIdentifier=mydotnetapp
User=www-data
Environment=DOTNET_ENVIRONMENT=Production

[Install]
WantedBy=multi-user.target
  1. Run:
sudo systemctl daemon-reexec
sudo systemctl enable mydotnetapp
sudo systemctl start mydotnetapp

💡 You can check status with systemctl status mydotnetapp or view logs using journalctl -u mydotnetapp


Common Problems & Fixes

“No such file or directory”

Check if the app executable has execution permissions:

chmod +x MyAppExecutable

“Cannot run app: missing dependencies”

Make sure you used --self-contained true or install the required runtime via apt install dotnet-runtime-6.0.

“404 errors or config missing”

Make sure appsettings.json and other required files are copied correctly.


Conclusion

Running a .NET app on Linux is very feasible with modern .NET. Whether you’re a startup building your first MVP or a developer moving to cloud-native infrastructure, this workflow allows for fast and efficient deployment across platforms.

Want help automating deployment? Integrate this with GitHub Actions or GitLab CI for full DevOps power.

This article is inspired by real-world challenges we tackle in our projects. If you're looking for expert solutions or need a team to bring your idea to life,

Let's talk!

    Please fill your details, and we will contact you back

      Please fill your details, and we will contact you back