Header

Automating deployments of your .NET Core project with DeployHQ

This guide assumes you already have a hosted server with ASP.NET Core set up and a project ready for deployment.

We'll be using DeployHQ to automate the deployment process whenever you push code to your version control system. The free plan allows you deploy 1 project up to 10 times a day!

Create a DeployHQ project

  1. Sign up and log in to DeployHQ.
  2. Navigate to Projects > New Project.
  3. Follow the wizard to choose the repository you want to deploy.

Configure a server in DeployHQ

  1. Go to Servers > New Server.
  2. Choose a name for your server and select SSH from the list of connection protocols.
  3. Enter your server's IP address in the Hostname field.
  4. Set the Username to a user with appropriate permissions on your server. For security reasons, it's recommended to create a dedicated user for deployments.
  5. Enable Use SSH key rather than password for authentication?

Here's how to generate the SSH key on your server:

 su - your_deployment_user  # Replace 'your_deployment_user' with your actual username
 mkdir ~/.ssh
 chmod 700 ~/.ssh
 nano ~/.ssh/authorized_keys
  1. Copy the public key provided by DeployHQ and paste it into the authorized_keys file.
  2. Save the file (Ctrl+O, then Enter) and exit the editor (Ctrl+X).
  3. Set the permissions on the authorized_keys file:
chmod 600 ~/.ssh/authorized_keys
  1. Set the Deployment Path to the location where your application files should be deployed on the server.
  2. Enable the Perform zero-downtime deployments on this server option (optional).
  3. Set the Environment field to a name that reflects your deployment environment (e.g. production).
  4. Click Save.

Add deployment configuration files (optional)

Config files allow you to upload sensitive information like environment variables to the server without storing them in your version control system.

  1. Go to Config Files and click New Config File.
  2. Paste the contents of your .NET Core environment variable file (e.g. .env) into the config file content field.

Set up SSH commands

DeployHQ allows you to run commands on the server after every deployment.

  1. Go to SSH Commands and click New SSH Command.
  2. Create the following commands:
  • Navigate to project directory:
cd %path%
  • Restore dependencies:
dotnet restore
  • Build the project:
dotnet publish -c Release
  • (Optional) Run database migrations:
dotnet ef database update
  • (Optional) Restart your application:
# How to restart your application will vary depending on how it's hosted
# Replace this with the appropriate command for your setup
# (e.g. systemctl restart your_app_service)

Note: Make sure to order the commands appropriately so they run in the correct sequence.

Deploy your project

  1. Click Deploy Project in the DeployHQ dashboard.
  2. Verify the server, start and end revisions (if applicable) and click Deploy to begin the deployment process.

Now DeployHQ will take care of deploying your project whenever you push code!

If you’ve got any other projects you’d like to automate deployments for, we’ve written lots of guides for deploying the most popular application frameworks and content management systems.

Tree

Proudly powered by Katapult. Running on 100% renewable energy.