In this tutorial, I will share a MsBuild snippet that will allow you to upload a file to a remote S3 bucket. Recently, I had a requirement to upload some JSON files and several DLL's onto an environment after a build on the build server was completed successfully. The client didn't want to use an extra tool, they also didn't want to check non-website related files into their repository. This is why we needed a script to manually transfer the files 😔 In most situations, I recommend using a deployment tool like Octopus Deploy. Octopus deploy will allow for file copying easily with clicks, not code.

My final solution involved using Amazon S3 to sync the files to the server. Amazon S3 (Amazon Simple Storage Service) is a cloud storage solution similar to dropbox. Instead of storing files on your own web server, S3 was designed to make file sharing quicker, more scalable and easier for applications to share files. In order to use S3 as a deployment tool, we had to create a build script that copied certain files from a designated folder into a zip and then upload that ZIP file onto S3. In our build server, we then needed to reverse the process and create a script to copy the zip file from S3 and extract it onto our testing server. The snippet below can be used for the upload part:

This snippet should copy all files in a folder called files and upload them into S3 for you. All you need to do is plug in the details and create the folder 😊

Happy Coding 🤘