Setting up Web Deploy with Visual Studio 2015

Visual Studio has a number of options for deployment but one of the most useful is the Web Publish option. This allows developers to not only push files directly to a server from Visual Studio, but also inspect the changes and only upload files that have been updated. This may not be viable in all situations but it can be very handy for fast and frequent deployments during development or testing.

Web Deploy needs to be configured on the destination server before it can be used as follows.

Add the web deploy feature to IIS

First check if this has already been setup on the destination server, if not it can be added via the Web Platform Installer. There are a few different options here depending on weather you need to deploy to SQL server or not. If you look for Web Deploy 3.5 this will cover most use cases.

Setup the target website in IIS if is not already present.

You now need a location to deploy to, you do not need to do much more than setup a folder location and site in IIS that your eventual deployment will run against.

Setup user accounts that should have authority to deploy.

These accounts are setup in IIS Manager and should only have permissions on the site you are deploying to. This can be found on the Web site screen in IIS that you just setup. Under IIS Manager Permissions you can setup a deployment user by selecting Allow User. Note this is a Windows user so you may also need to create the user separately on the server.

Generate the Web Deploy Publishing Configuration

While in the IIS Management console, right click on the website you want to deploy to and select Configure Web Deploy publishing. This will bring up a new window with various options. Here you just need to specify the user you set up in the previous step as the publishing user and the URL for the publishing server connection. Note you will need to be able to access the server directly via the publishing URL from your development machine, so you may need to change the publishing URL to use the servers public IP rather than server name which seems to be the default. Once complete you can select setup. This will save a config file to the desktop for import into Visual Studio.

Add access rules to restrict by IP

As a further security measure you can restrict access so that only your own IP can deploy to the server. Obviously this can be a problem if you do not deploy from a static IP but it is fairly easy to update as required for an extra piece of mind. To do this click on the main server node and select the Management Service feature. Here you can specify a number of IP restrictions. Note you will need to stop the server temporarily to make the changes.

Enable web deploy to download publish config

The publish config file saved from the server allows a quick import into Visual Studio rather than having to setup everything manually. This is saved to the desktop by default and can then be copied to your development machine. All this does is provide an easy way to import deployment configurations into Visual Studio.

Ensure services are running

In order to connect to the server to publish the World Wide Web Publishing Service and the Windows Remote Management Service need to be running, so before attempting a publish make sure these services are running on the server.

Setup publishing to use web deploy in Visual Studio project

There are a number of different options for publishing in Visual Studio with web deploy the config file you downloaded from the server can simply be used to create the publishing target in Visual Studio. With your solution open right click on the Website project and select publish.

From here you can create a new Profile name it something memorable and then select the publish target.

You will want to select Import to use the config file you generated on the server. This will populate most of the Settings screen for you but you will still need to set the password. This will be the windows user credentials that you created earlier. Once complete you can Validate the connection to ensure the credentials are correct. 

Deploy with preview

Once the connection has been tested and all the security settings confirmed you can preview the publish. This will display a list of all the files that will be deployed to the server on publish and you can even see what the differences are prior to deployment. When you are happy with the changes click Publish and Visual Studio will push the files up to the server for you.