Publish Web App from Visual Studio to IIS Using Web Deploy
Tags: devops, productivity, tutorial
Published: 2022-04-04 20:12:14

## Introduction

There are several ways you could publish your Web App from Visual Studio. The simplest way is to publish to a folder, then copy paste to the hosting server, IIS for example.

But it's always better to automate these operations; it makes them faster (no need to copy all files, just the changed ones), and less likely to cause mistakes (replace appsettings.json or web.config file).
It also opens the door to more advanced operations, like zero downtime deployment, which I plan to write about in the next post.

In this post I'll write about how to publish a Web App in Visual Studio to IIS using Web Deploy. When things are set up, you will only need to click the publish button in Visual Studio to publish your app.

[What is Web Deploy?](https://docs.microsoft.com/en-us/iis/publish/using-web-deploy/introduction-to-web-deploy)

## Prerequisites

* IIS 7
* Visual Studio 2010

## Steps

_Note: The order of steps is important._

### 1. Install Web Management Service (WMSVC)

1. In remote server, open Control Panel -> Turn Windows features on or off.
2. Look for Internet Information Services (IIS) -> Management Tools -> check Management Service.
3. Proceed to install.

![Check Management Service](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/veu44d12yy13snavfjgt.png)
 
### 2. Download and Install Web Platform Installer (WebPI)

It's recommended to use WebPI instead of directly downloading tools; because WebPI also gets the dependencies and configures these tools depending on the current system settings.

[Web Platform Installer](https://www.microsoft.com/web/downloads/platform.aspx)

### 3. Get Web Deploy

1. Open WebPI directly (start menu for example), not through IIS Manager.
2. Search for Web Deploy, then install.

![Install Web Deploy from WebPI](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/y01g8w89r99nc988s53h.png)

_Note: If Web Deploy is already installed, uninstall it (from Control Panel, not repair), then repeat above steps._

### 4. Add Port 8172 to Exceptions

This port gets added automatically to Windows Firewall exceptions if you followed the above steps.

Make sure the port is open through the path from the development environment to the hosting server, for example if you are using EC2, add the port to the Inbound Rules of the Security Group.

### 5. Create New Publish Profile in Visual Studio

1. Open the project you want to publish, then create a new publish profile.
3. Select Web Server (IIS) -> Web Deploy.
4. Write the server details as follow:
   * Server: `https://(ip or name):8172/msdeploy.axd`
   * Site name: `site/application` as in IIS
   * Username and Password are windows credentials.
5. Click Finish.
6. You might need to add `<AllowUntrustedCertificate>True</AllowUntrustedCertificate>` to the publish profile found under solution tree: YourProject -> Properties -> PublishProfiles.

![Publish Profile](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0zl4rx7ph8vl7nqi8g8x.png)

### 6. Publish Your Project

We finished setting up Web Deploy, now you just need to click publish, and Web Deploy will do all the work for you.

## See Also
[Web Deploy with command line](https://docs.microsoft.com/en-us/previous-versions/windows/it-pro/windows-server-2008-R2-and-2008/dd568996(v=ws.10))