Set Up ASP .NET Pipeline in 5 Simple Steps
To ensure a successful deployment of your files to the desired FTP location, your pipeline should:
- Activate immediately after a commit to a specified branch (e.g., master).
- Utilize the latest Windows machine for building the solution in 'Release' mode.
- Restore NuGet packages.
- Export the web app to a designated file system directory.
- Transfer the files to the FTP server with the FtpUpload task. For a deeper understanding, consider checking Microsoft's official documentation on the FTPUpload task.
Complete Azure pipeline YAML with FtpUpload task
This YAML file outlines the Azure DevOps pipeline for an ASP.NET application, specifying the build and deployment process.
Let me break down its main components for clarity:
Triggers and Environment:
- The pipeline is triggered whenever there's a commit to the master branch.
- It uses the latest Windows virtual machine image.
- Defines the solution files, build platform, and configuration.
a. NuGet Setup:
- First, the pipeline ensures that the NuGet tool is installed.
- Then, it restores any missing packages using the NuGet command.
b. Building the Solution:
- It uses the Visual Studio Build (VSBuild) task to build the specified solution.
- The build configuration is set to Release, and it publishes the web app to a file system directory.
- After building, the pipeline runs tests using the VSTest task.
d. FTP Upload:
- The last task, FtpUpload, uploads the built website to an FTP server.
- It uses the specified credentials to connect to the server.
- The files from the artifact staging directory are uploaded to the /wwwroot directory of the server.
- This task has several configuration options like preserving paths, trusting SSL, etc.
# 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
Please ensure to modify sensitive details like the username and password before deploying.
Also, remember to adjust the serverUrl from its placeholder value (ftp://127.0.0.1) to your actual FTP server's address.
Get the Source Code and Stay Updated
For an in-depth exploration and hands-on experience, download the source code for this article directly from GitHub repository
And for the latest updates, tips, and more developer insights, don't forget to follow us on Social Media!
Your support keeps us motivated to produce more content like this.