| |

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

What you will learn

In this post, I will show how to configure the Azure DevOps pipeline – to easily publish an ASP .NET app to FTP server.

How to configure the pipeline (5 easy steps)

FtpUpload task is essential, please check the last step. To deploy all your files to the desired FTP location, the pipeline should:

  • Trigger after committing to the branch (ex. master).
  • Use the latest windows machine to build a solution in Release mode.
  • Restore the missing NuGet packages.
  • Publish web app to file system folder.
  • Upload the files to the FTP server using the FtpUpload task (Read more about the FTPUpload task on Microsoft’s docs page).

Azure pipelines YAML with FtpUpload task

The complete azure-pipelines.yml file looks as follows:

# 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

- master

  vmImage: 'windows-latest'

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

- task: NuGetToolInstaller@1

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

- task: VSBuild@1
    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
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'

- task: FtpUpload@2
    credentialsOption: 'inputs'
    serverUrl: ''
    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

Download the code

To download the source code for this post, please visit GitHub

Similar Posts