How to use github actions to auto publish your website file to our server.

Programming, error messages and sample code > ASP.NET

Create a GitHub Workflow to Build, Publish, and Deploy a Project to SharkASP.NET

Follow the steps below to automate the build and deployment of your project to SharkASP.NET using GitHub Actions.

Step 1: Open Your Repository

Navigate to the GitHub repository that you want to deploy automatically.

Step 2: Go to the Actions Tab

Select the Actions tab from the repository navigation menu.

Step 3: Create a New Workflow

Select:

Set up a workflow yourself

Step 4: Add a Workflow File

Create a workflow file under:

.github/workflows/

Then copy and paste one of the following deployment methods into the .yml file and commit it to your repository.

Option 1: FTP Deployment

Use this option if you prefer deploying your files via FTP.

name: Build Project and Deploy to SharkASP.NET

on: [push]

jobs:
  build_and_deploy:
    name: Build Package and Deploy
    runs-on: windows-latest

    steps:
      - name: Checkout Source Code
        uses: actions/checkout@v4

      - name: Deploy Files via FTP
        uses: SamKirkland/[email protected]
        with:
          server: winxxxx.site4now.net
          username: xxxxxx
          password: xxxxxxxxxxx

Option 2: Web Deploy (Recommended)

This method is recommended for ASP.NET and ASP.NET Core applications.

name: Build, Publish, and Deploy Project to SharkASP.NET

on:
  push:
    branches:
      - main

jobs:
  build_and_deploy:
    runs-on: windows-latest

    steps:
      - name: Checkout Source Code
        uses: actions/checkout@v4

      - name: Setup .NET
        uses: actions/setup-dotnet@v4
        with:
          dotnet-version: '10.x'

      - name: Restore Dependencies
        run: dotnet restore

      - name: Build Project
        run: dotnet build --configuration Release --no-restore

      - name: Run Tests
        run: dotnet test --configuration Release --no-build

      - name: Publish Application
        run: dotnet publish --configuration Release --no-build --output ./release

      - name: Deploy to SharkASP.NET
        shell: powershell
        run: |
          $msdeploy = "C:\Program Files\IIS\Microsoft Web Deploy V3\msdeploy.exe"

          $siteName = '${{ secrets.WEBSITE_NAME }}'
          $computer = '${{ secrets.SERVER_COMPUTER_NAME }}'
          $user     = '${{ secrets.SERVER_USERNAME }}'
          $password = '${{ secrets.SERVER_PASSWORD }}'

          & $msdeploy `
            -verb:sync `
            -source:contentPath="$(pwd)\release" `
            -dest:contentPath="$siteName",ComputerName="$computer",UserName="$user",Password="$password",AuthType="Basic" `
            -allowUntrusted `
            -enableRule:AppOffline `
            -enableRule:DoNotDeleteRule

Step 5: Configure GitHub Secrets

Navigate to:

Settings → Secrets and variables → Actions → New repository secret

Create the following repository secrets:

Secret Name Required Description Example
WEBSITE_NAME Yes Your Web Deploy site name username-001-site1
SERVER_COMPUTER_NAME Yes Your Web Deploy service URL https://winxxxx.site4now.net:8172/MsDeploy.axd?site=username-001-site1
SERVER_USERNAME Yes Your Web Deploy username username-001
SERVER_PASSWORD Yes Your Web Deploy password your-password

Example Configuration

WEBSITE_NAME=username-001-site1

SERVER_COMPUTER_NAME=https://winxxxx.site4now.net:8172/MsDeploy.axd?site=username-001-site1

SERVER_USERNAME=username-001

SERVER_PASSWORD=your-password

Step 6: Automatic Deployment

After configuring the required secrets, the workflow will automatically run whenever code is pushed to the configured branch.

The workflow performs the following tasks:

  1. Restore project dependencies
  2. Build the application
  3. Run automated tests
  4. Publish the application
  5. Deploy the application to SharkASP.NET

You can monitor deployment progress and review execution logs from the Actions tab in your GitHub repository.

Tip: GitHub Actions workflows are highly customizable. You can extend this workflow with multi-environment deployments, approval gates, notifications, rollback strategies, and more.