Deploying ASP .NET app to FTP with Azure DevOps CI/CD pipeline

Introduction

In this post, I will show how to configure the Azure DevOps pipeline - to easily publish an ASP .NET app to FTP server. The core part of the pipeline is VSBuild and FTPUpload task.

How does the azure pipeline work?

  • Triggers after committing to the master branch
  • Uses the latest windows machine to build a solution in Release mode
  • Restores the missing NuGet packages
  • Publishes web app to file system folder
  • Uploads the files to the FTP server using the FtpUpload task (Read more about the FTPUpload task on Microsoft's docs page).

Full azure-pipelines.yml YAML code

# ASP.NET
# Build and test ASP.NET projects.
# Add steps that publish symbols, save build artifacts, deploy, and more:
# https://docs.microsoft.com/azure/devops/pipelines/apps/aspnet/build-aspnet-4

trigger:
- master

pool:
  vmImage: 'windows-latest'

variables:
  solution: '**/*.sln'
  buildPlatform: 'Any CPU'
  buildConfiguration: 'Release'

steps:
- task: NuGetToolInstaller@1

- task: NuGetCommand@2
  inputs:
    restoreSolution: '$(solution)'

- task: VSBuild@1
  inputs:
    solution: '$(solution)'
    msbuildArgs: '/p:DeployOnBuild=true /p:DeployDefaultTarget=WebPublish /p:WebPublishMethod=FileSystem /p:SkipInvalidConfigurations=true /p:publishUrl=$(build.artifactstagingdirectory)\website'
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'

- task: VSTest@2
  inputs:
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'

- task: FtpUpload@2
  inputs:
    credentialsOption: 'inputs'
    serverUrl: 'ftp://127.0.0.1'
    username: 'ftp-user-name'
    password: 'P@ssword'
    rootDirectory: '$(build.artifactStagingDirectory)/website'
    filePatterns: '**'
    remoteDirectory: '/wwwroot' # '/wwwroot/$(Build.BuildId)/'
    clean: false
    cleanContents: false
    preservePaths: true
    trustSSL: false
To download the source code for this post, please visit GitHub
Comments
Leave a Comment