Publishing with Web Deploy in WebMatrix

Share this article

The previous articles in our WebMatrix series have taken you through using the Web App Gallery to build an ecommerce site and find the right CMS, building dynamic websites with WebMatrix, and hosting, publishing and generating traffic with WebMatrix.

In all of that, we acknowledged but didn’t go into much detail about a particular WebMatrix functionality called Web Deploy. That’s because our focus has been on the hands-on pro developer, and one of Web Deploy’s great strengths is that it make publishing a website easier for beginner or hobby developers.

But that doesn’t mean we shouldn’t be interested in Web Deploy. In a forthcoming article, you’ll read about why the WebMatrix suite is, in fact, a very handy set of tools for the most advanced developers. For now, let’s dig into Web Deploy.

This article assumes you have either read the earlier articles referred to, or have already installed WebMatrix.

In a nutshell, Web Deploy runs on a server and gives you the ability to deploy websites locally or remotely.  In doing so, it takes care of a plethora of tasks and processes that might otherwise be handled manually.

Why Web Deploy?

Developing and designing a website or web application is one thing, but deployment – publishing to a web server – has always been tricky at the best of times.  Web Deploy greatly simplifies the migration, management and deployment of websites.  Web Deploy not only copies files and folders, it can perform configuration transformation, provision database schemes as well as the data, package dependencies such as COM objects, install SSL certificates and a number of other features.

An example of Web Deploy’s approach is that it use differential uploading to only transfer modified files, saving you time and work.

Web Deploy also supports a .NET based provider API that gives you the ability to create custom deployment actions, so it’s a perfect fit for the enterprise.  It’s part of an approach designed to make it easy to move painlessly from having an idea for a website to declaring it open for business.

Installation

When you install WebMatrix through the Web Platform Installer, Web Deploy is automatically installed as a dependency.  See Figure 1, “Web Platform Installer Dependencies”.

Figure 1.  Web Platform Installer Dependencies

figure 1

Upon completion, Web Deploy is installed to the C:Program FilesIISMicrosoft Web Deploy V2 directory.  The actual file that is executed when you run Web Deploy is msdeploy.exe.  This file lets you do some rather clever things, but for now just be aware that every Web Deploy example in this article ultimately executes this file.

Deploying Databases

If you’re using SQL Server Compact as your database, the data is stored in an .sdf file in the App_Data folder in your website. When you publish the database, WebMatrix copies not only the .sdf file but also the database program itself to the web server. This ensures that the published site will work even if SQL Server Compact isn’t already installed on the web server.  The big advantage of this is you don’t need a separate script to create the database schema and optionally insert the data.  It’s all done for you.

If you’re using a SQL Server or MySQL database, WebMatrix publishes the database by creating scripts that run in a database that has been created for you by your hosting provider. These scripts create database tables and insert data into them in order to replicate the structure and data that you have in the database on your computer.

For this article I’m going to use SQL Server Compact to demonstrate how easy Web Deploy makes database deployments.

Finding and Creating a Web Host Account

If you’re going to publish your site on the web, you’ll probably need to find a hosting provider.  This task is simplified by WebMatrix.  To set up web hosting, follow these steps.

  1. Open WebMatrix and in the Home tab, expand Publish and choose Find Web Hosting as Figure 2, “Find Web Hosting” shows.

    Figure 2.  Find Web Hosting

    figure 2

  2. The Windows Web Hosting Gallery website will open.  Figure 3, “Windows Web Hosting Gallery” shows how you can search through the list of providers to find the right hosting solution for your needs.

    Figure 3.  Windows Web Hosting Gallery

    figure 3

Once you’ve decided on a hosting provider, follow the directions provided by the hosting provider’s site to set up your new account.

After your account is set up, the hosting provider sends you an email that contains information you’ll need in order to publish your website. These values may vary from host to host, but the common values might look like this:

  • Server: your.provider.com
  • User Name: your.username
  • Password: password
  • Site Name: yoursite.your.provider.com
  • Destination URL: http:// yoursite .your.provider.com

If your account includes a SQL Server database, you’ll also receive information about how to connect to it.  Typically the database connection string will look like this:

User ID=user;Password=password;Initial Catalog=databaseName;Data Source=sql.host

These values can be entered into WebMatrix which will allow you to publish your website to your host.  Some hosting providers will send you a Publish Settings File, which is a file with the .publishsettings extension.  This is an XML file you can use when you configure your website for publishing to the host provider.  This saves you having to manually type in the data.  If your website connects to a database and you’re using Web Deploy, the file will also include the database connection strings.

Configuring Your Website for Publishing with SQL Server Compact

The next step is to configure the website before publishing it to the web host.

  1. Open WebMatrix and in the Home tab, expand Publish and choose Settings as Figure 4, “Web Hosting Settings” shows.

    Figure 4.  Web Hosting Settings

    figure 4

    The Publishing Settings window appears.  This is highlighted in Figure 5, “Publishing Settings”.

    Figure 5.  Publishing Settings

    figure 5

  2. Using Web Deploy as the Protocol, enter the Server, User name, Password, Site name and Destination URL that has been provided to you from your hosting provider.  Here’s a breakdown of what these values are:
    1. Server – this is the server name provided by your hosting provider.  An example of this is https://webserver.winhost.com:8172/MsDeploy.axd (Replace webserver with the actual server name, for example: w07).
    2. User name – the user credential provided by your hosting provider.
    3. Password – the password you entered when you signed up with your hosting provider.
    4. Site name – the path you want the application uploaded to. This could be accountdomain.com or accountdomain.com/subdirectory.  Don’t include http://www in this field.
    5. Destination URL – the URL to your website.  The Hypertext Transfer Protocol (HTTP) is not required.  You can enter http://www.yourwebsite.com or http://www.yourwebsite.com/wiki.
  3. To avoid having to re-type the password for each deployment, you can select Save password.
  4. The database name will be displayed also.  The message Remote connection string not required is displayed.  This is because SQL Server Compact will be packaged into the deployment, so no remote database connections are needed.  The connection string resides in the web.config file. Note that if you were using an SQL database, this is where you would add the database connection string we referred to earlier (User ID=user;Password=password;Initial Catalog=databaseName;Data Source=sql.host).
  5. Click Validate Connectionto verify WebMatrix is able to connect to your hosting provider.  This is highlighted in Figure 6, “Validating the Connection”.

    Figure 6.  Validating the Connection

    figure 6

Publishing

The last piece of the puzzle is to publish the website.  Once again this is easily achieved through WebMatrix.  Before publishing any files, WebMatrix collates the files that will be published so you can make changes if required.  Follow these steps to publish the website to your hosting provider.

  1. Open WebMatrix and in the Home tab, expand Publish and choose Publish...  The Publish Preview window appears.  Using this screen, you can modify any files if required.  If you don’t want a file to be published, clear the check box under Changed Files.  Any file that has a clear check box won’t be published.  It is vitally importantto remember if you do deploy a database, and it already exists on the hosting provider, the existing database will be overwritten.  Finally you must remember to copy the database as part of the deployment.  This is accomplished by selecting the check box next to the database name.  Figure 7, “Publish Preview” shows you what’s going to be deployed.

    Figure 7.  Publish Preview

    figure 7

    You can also choose to delete all files that aren’t on your local computer from the web server before the deployment begins.  Selecting Delete files on the remote server that are not on my computer enables this function.

  2. Once you’ve made your decision on what files to publish, click Continue.  WebMatrix will now publish all of the files behind the scenes, which means you can continue working in WebMatrix while still publishing.  It will display the progress in the navigation bar in the bottom of the screen.  This can be seen in Figure 8, “Publishing Status”.

    Figure 8.  Publishing Status

    figure 8

    At anytime you can click Log in the navigation bar to view which step the publishing process is up to.  Figure 9, “Publishing Log” depicts this screen.

    Figure 9.  Publishing Log

    figure 9

Summary

It’s not hard to see that Web Deploy simplifies much of the fiddly configuration detail that often trips up the publishing of a website or web application. In doing so, it appeals to the less experienced developer but also becomes a valuable tool for a pro developer who moves quickly between localhost prototyping and testing live sites.

SitePoint Content Partner

This tutorial has been made possible by the support of Microsoft. In cooperation with Microsoft and independently written by SitePoint, we strive to work together to develop the content that’s most useful and relevant to you.

I’ve found WebMatrix to be very handy as a development tool, particularly in testing combinations of apps to create specific functionality on ASP.NET websites. If I use Web Deploy, I can set WebMatrix up to download an existing website, edit it, test it and upload it again.

Along with the impressive Razor syntax, the size and robustness of SQL Compact and the way IIS Express combines the strengths of ASP.Net Development Server and IIS Web Server, Web Deploy’s ease of use helps to make WebMatrix an ASP.NET editing suite worth serious consideration.

Good starting points for further information are the Web Deploy 2.0 and WebMatrix websites.


The article sequence:

Malcolm SheridanMalcolm Sheridan
View Author

Malcolm Sheridan is a Microsoft awarded MVP in ASP.NET, ASPInsider, Telerik Insider and a regular presenter at conferences and user groups throughout Australia and New Zealand. Follow him on twitter @malcolmsheridan.

Web Deploywebmatrix
Share this article
Read Next
Get the freshest news and resources for developers, designers and digital creators in your inbox each week