If you’re like most software developers, you probably use Visual Studio to develop and deploy your applications. But what if you don’t have a FTP account? Or if you don’t want to use FTP, how can you automate deployments of your applications with Visual Studio and FTP? The first way is to create a new project in Visual Studio and then add an application into it. The second way is to use the Add-App Wizard. The Add-App Wizard will help you create a new application and add it to your project. The Add-App Wizard can be used in two ways: when you’re creating an application from scratch or when you’re using an existing application that has been converted to use Visual Studio and FTP. When using the Add-App Wizard, follow these steps:

  1. In the Project Explorer, right-click on the project name and select New Item. The New Item dialog will appear.
  2. In the New Item dialog, enter FTP into the Name field and click on OK.
  3. In the Project Explorer, right-click on the newly created FTP application and select Properties from the context menu.
  4. In the Properties dialog, enter a name for your FTP application (for example, MyFTPApplication) and click on OK.
  5. Right-click on MyFTPApplication in the Project Explorer and select Deployment from the context menu; this will open up a Deployment window that will look similar to Figure 1 below: Figure 1: The Add-App Wizard for deploying an existing FTP application

Visual Studio has options to automatically publish your release build to remote servers over FTP. This can be very useful if you’re deploying changes often or testing in a remote environment. We’ll show you how to set it up and talk about how it works.

Publishing via FTP

FTP is an old, generally insecure protocol, but as long as your FTP server supports the modern extensions of FTPS, which uses TLS encryption, it should be fine. You can also chroot your FTP users so that they can only write to the target directory.

You can read our guide to setting up an FTP server to learn more. You’ll want to make sure that FTPS is set up and that regular FTP is disabled.

RELATED: How to Set Up a Linux FTP Server for Quick File Transfers

Not all types of builds are supported, though. Class libraries, for example, have no options to publish. ASP.NET Core applications are supported better and have options to publish to Azure and Docker.

Luckily, for the applications that aren’t supported, you can hook it up yourself, as Visual Studio also offers options to run post-build PowerShell scripts. These will run on build instead of on-publish, but you can just set up a custom “publish” build profile with copied release settings.

You can use these post-build scripts to make FTP or SCP transfers, or even to connect to external services like AWS S3 or a Docker Registry.

Setting Up Visual Studio

Under build, you should see an option to publish your solution. If you don’t see this, you’ll need to skip to the backup option of using post-build scripts.

You’ll need to make a new publish profile or edit the default one. Select FTPS Server, although you can publish to Azure, Docker, a local folder, or IIS web deploy if those work better for you.

Enter in the details of the connection. You’ll need to give it a URL, a path to where it’s going to upload, and a username/password.

Then, click publish, and you should see it transfer in the console after the build is complete. If it doesn’t, you’ll get an error or a log file where you can troubleshoot it.

Setting Up Post-Build Scripts for Other Applications

Visual Studio’s built-in options are great, but when they don’t work, you’ll need to do a bit of scripting. Right-click your project and select “Properties”:

Then, under “Build Events,” you can set up a post-build command. Note that this is cmd, so you’ll need to manually call PowerShell, and this is also scoped to the output folder of the build, so if you’re storing the PowerShell script at the root of your project, you might need to reference it a few directories up with …….

Set it to run on post-build, and you can choose whether to run the script always, whenever it’s successful, or whenever the build gets updated. If you’re restarting servers or something, you’ll only want to run the script when it’s updated. Otherwise, select “on successful build” unless you have a reason to be running the script when the build fails.

PowerShell doesn’t have built-in support for FTP. You have two options—use PowerShell Remoting over SSH to transfer to a Linux server, or use a PowerShell library for FTP.

If you need to use FTP, WinSCP can handle the transfer pretty easily.

In either case, you’ll need to make sure that your script has correct references to the proper file locations. If you click “Edit Post-Build,” you’ll see a window listing all the variables that you can pass to your script.