Gal Ratner
Gal Ratner is a Techie who lives and works in Los Angeles CA and Austin TX. Follow galratner on Twitter Google
How to deploy a web application into IIS7 in 10 minutes using Web Deployment Tool

Web Deployment Tool is a part of Web Platform Installer distributed by Microsoft and can be downloaded at http://www.microsoft.com/Web/


Web Deployment Tool can deploy a web package into IIS 7, saving you the need to copy files and dlls around, installing databases and making conformation changes for you.
In order to utilize the installer you need to build a web package
Building the Web Package
The Web Package usually consists of four parts:
Your website folder - Contains your complete website starting from the root folder.
manifest.xml – contains the guidelines for the site’s folders and database script locations.

- <msdeploy.iisapp>

  <iisapp path="ShoppingCartNet" />

  <dbfullsql path="install.sql" transacted="false" />

  <setAcl path="ShoppingCartNet/ProductImages/" setAclResourceType="Directory" setAclAccess="Read,Write,Modify" setAclUser="anonymousAuthenticationUser" />

  </msdeploy.iisapp>

 
parameters.xml – contains all of the parameters needed for SQL install users, string connections and application names

- <parameters>

- <parameter name="Application Path" description="Full site path where you would like to install your application (for example, Default Web Site/Application)." defaultValue="Default Web Site/ShoppingCartNet" tags="iisapp">

  <parameterEntry type="ProviderPath" scope="iisapp" match="ShoppingCartNet" />

  </parameter>

- <!--

 Prompts for database server name, this is used in the connection string parameter later


  -->

  <parameter name="Database Server" description="Location of your database server (i.e. server name, IP address, or server\instance)" defaultValue=".\SQLEXPRESS" tags="SQL, dbServer" />

- <!--

 Prompts for the database name and fills it into the database scripts


  -->

- <parameter name="Database Name" description="Name of the database for your application." defaultValue="ShoppingCartNet" tags="SQL, dbName">

  <parameterEntry type="TextFile" scope="install.sql" match="PlaceHolderForDb" />

  </parameter>

- <!--

 Prompts for the database username and fills it into the database scripts. The SQL tag indicates it is a parameter required for SQL, the DbUsername tag indicates this is a Db username


  -->

- <parameter name="Database Username" description="User name to access your application database." defaultValue="ShoppingCartNetUser" tags="SQL, dbUsername">

  <parameterEntry type="TextFile" scope="install.sql" match="PlaceHolderForUser" />

  </parameter>

- <!--

 Prompts for the database password and fills it into the database scripts. The SQL tag indicates it is a parameter required for SQL, the DbUserPassword tag indicates this is a Db password


  -->

- <parameter name="Database Password" description="Password for the database username." tags="New, Password, SQL, dbUserPassword">

  <parameterEntry type="TextFile" scope="install.sql" match="PlaceHolderForPassword" />

  </parameter>

- <!--

 Prompts for the admin creds and uses it for the administrator connection string. This is used to create a login and assign permissions. The SQL tag indicates it is a parameter required for SQL. The DbAdminUsername tag indicates it should be used when the user is creating a new database. If they're not, it can be filled in with the DbUsername value.


  -->

  <parameter name="Database Administrator" description="Administrator user name for your database." defaultValue="sa" tags="SQL, dbAdminUsername" />

- <!--

 Prompts for the admin password and uses it for the administrator connection string.  This is use to create a login and assign permissions. The SQL tag indicates it is a parameter required for SQL. The DbAdminPassword tag indicates it should be used when the user is creating a new database. If they're not, it can be filled in with the DbUserPassword value.


  -->

  <parameter name="Database Administrator Password" description="Password for the database administrator account." tags="Password, SQL, dbAdminPassword" />

- <!--

 This is the hidden admin connection string used to run the database scripts


  -->

- <parameter name="Connection String" description="Automatically sets the connection string for the connection request." defaultValue="Server={Database Server};Database={Database Name};uid={Database Administrator};Pwd={Database Administrator Password};" tags="Hidden">

  <parameterEntry type="ProviderPath" scope="dbfullsql" match="install.sql" />

  </parameter>

- <parameter name="Connection String For Config" description="Automatically sets the connection string for the Web.config." defaultValue="Data Source={Database Server};Database={Database Name};uid={Database Username};Pwd={Database Password};" tags="Hidden">

  <parameterEntry type="XmlFile" scope="\\web.config$" match="/configuration/connectionStrings/add[@name='StringConnection']/@connectionString" />

  </parameter>

- <parameter name="Connection String For Config Entities" description="Automatically sets the connection string Entities for the Web.config." defaultValue="metadata=res://*/Entities.CartModel.csdl|res://*/Entities.CartModel.ssdl|res://*/Entities.CartModel.msl;provider=System.Data.SqlClient;provider connection string="Data Source={Database Server};Database={Database Name};uid={Database Username};Pwd={Database Password};MultipleActiveResultSets=False"" tags="Hidden">

  <parameterEntry type="XmlFile" scope="\\web.config$" match="/configuration/connectionStrings/add[@name='Entities']/@connectionString" />

  </parameter>

- <!--

 This is the parameter that is used to set ACLs, it's set to the application path filled in by the user


  -->

- <parameter name="SetAclParameter1" description="Sets the ACL on the right file" defaultValue="{Application Path}/ProductImages/" tags="Hidden">

  <parameterEntry type="ProviderPath" scope="setAcl" match="ShoppingCartNet/ProductImages/" />

  </parameter>

  </parameters>

 


install.sql – contains the complete script for creating everything in your database including the uses used in the String Connection

 -- Declare variables for database name, username and password

DECLARE @dbName sysname,

      @dbUser sysname,

      @dbPwd nvarchar(max);

 

-- Set variables for database name, username and password

SET @dbName = 'PlaceHolderForDb';

SET @dbUser = 'PlaceHolderForUser';

SET @dbPwd = 'PlaceHolderForPassword';

 

DECLARE @cmd nvarchar(max)

 

-- Create login

IF( SUSER_SID(@dbUser) is null )

BEGIN

    print '-- Creating login '

    SET @cmd = N'CREATE LOGIN ' + quotename(@dbUser) + N' WITH PASSWORD ='''+ replace(@dbPwd, '''', '''''') + N''''

    EXEC(@cmd)

END

 

-- Create database user and map to login

-- and add user to the datareader, datawriter, ddladmin and securityadmin roles

--

SET @cmd = N'USE ' + quotename(@DBName) + N';

IF( NOT EXISTS (SELECT * FROM sys.database_principals WHERE name = ''' + replace(@dbUser, '''', '''''') + N'''))

BEGIN

    print ''-- Creating user'';

    CREATE USER ' + quotename(@dbUser) + N' FOR LOGIN ' + quotename(@dbUser) + N';

    print ''-- Adding user'';

    EXEC sp_addrolemember ''db_owner'', ''' + replace(@dbUser, '''', '''''') + N''';

END'

EXEC(@cmd)

GO

The rest of your SQL goes here...


Putting everything together
Simply use windows Zip to add all of the files to a zip file. If you added them correctly, everything will be at the root level of your packaged zip file.

 

Deploying

Simply ise IIS Manager to import your package.

That is all you need to quickly deploy a Web Application using Web Deployment Tool!

Want to learn more about Application Packaging? Visit the Application Packaging Guide for the Windows Web Application Gallery

I would like to thank Walter Oliver from the IIS Team for his help and guidance preparing my own Web Package and this blog post.

Shout it kick it on DotNetKicks.com


Posted 10 Oct 2009 8:41 PM by Gal Ratner
Filed under:

Comments

DotNetKicks.com wrote How to deploy a web application into IIS7 with Web Deployment Tool
on 10 Oct 2009 1:43 PM

You've been kicked (a good thing) - Trackback from DotNetKicks.com

DotNetShoutout wrote How to deploy a web application into IIS7 in 10 minutes using Web Deployment Tool - .NET Development - Gal Ratner
on 10 Oct 2009 1:46 PM

Thank you for submitting this cool story - Trackback from DotNetShoutout

JACKY wrote re: How to deploy a web application into IIS7 in 10 minutes using Web Deployment Tool
on 10 Oct 2009 9:28 PM

Nice one. I will try it. :)

Powered by Community Server (Non-Commercial Edition), by Telligent Systems