Resources

Process required to deploy ASP.NET websites

Publishing Web Applications

By default website are entirely file based. Source code usually deployed to server which then compiles that code when a page is requested. In this scenario deploy website by copying files to correct directory.

When deploying new version of site, simply overwrite old files with new ones.

Configuration settings defined within web.config and application code contained entirely within website folder structure.

Simplicity => flexibility. To deploy to array of servers use file sync tool to copy files between serves.

If website has database, requires special web server configuration, needs different config settings between staging and release environments, etc. then publishing involves:

Visual Studio Publish Web dialogue allows these settings to be set once and then pushed to one (or more) web servers.

Web.config Transformations

Application settings differ between development, staging and live environments.

Web.config transformations allow separate web.config to be created for each environment.

Only need to specify settings to be added, changed or removed from base Web.config file.

By default transformations added for debug and release configurations.

View transformations by expanding Web.Config node and then opening web.config.debug or web.config.release

If defined new configurations, e.g. staging, then aff associated transformation by right-clicking Web.config and selecting Add Config Transformations.

Adding setting

Simply add the setting to the web.config transformation file.

Replace setting

Add element to web.config transformation file with attribute of xdt:Transform="Replace":

<configuration>

<system.web>

<customErrors defaultRedirect="GenericError.htm" xdt:Transform="Replace">

<error statusCode="500" redirect="InternalError.htm"/>

</customErrors>

</system.web>

</configuration>

Can specify conditions on which replacement to occur via the xdt:Locator attribute:

<configuration>

<connectionStrings>

<add name="MyDB" connectionstring="conn string" xdt:Transform="Replace" xdt:Locator="Condition(@name='oldname')" />

</customErrors>

</connectionStrings>

</configuration>

Without the locator attribute all connection strings would be replaced.

Removing Setting

Set the xdt:Transform attribute to RemoveAttributes() method, passing it the attribute to remove, e.g.:

<configuration>

<system.web>

<compilation xdt:Transform="RemoveAttributes(debug)" />

</system.web>

</configuration>

Configuring Deployment

Configure databases to deploy by right clicking project, going to Package/Publish SQL Settings.

Can use Import From Web.config button to configure any database already in web.config

If database does not exist on server deploying to then select Pull Data And./r Schema From An Existing Database check box. Use the Database Scripting Options list to choose between deploying schema, data, or both. Can also add SQL scripts to perform additional, custom configuration.

Package/Publish Web tab offers additional deployment options, e.g. which files to include, compression and encryption options, whether IIS settings not specified in web.config should be packaged, etc.

Publishing Website

Right click and choose Publish.

Can save publish settings by providing it with a profile name. Settings include:

Deployment Packages

If not deploying directly, can package website into zip file for system administrators to install.

Destination server must have Web Deploy installed on it.

Zip file contains application.deploy.cmd which is sued to install deployment.

Web Deployment Projects

Post Visual Studio 2010 release by Microsoft.

Extends Visual Studio by adding UI to manage build configurations, merging and pre / post build tasks.

Allow site to be pre-compiled.

Can merge all files into single assembly, or assemblies for each page / control.

Provides strong naming of assemblies

Web Setup Projects

Publishing websites requires specially configured web servers that permit publication to take place. Further, does not support distribution infrastructures requiring MSI packages.

Web Setup Projects provide highest level of deployment flexibility.

Creating Web Setup Project

Similar to standard setup projects

Select File | Add | New Project | Add New Project

From available templates expand Other Project Types | Setup And Deployment | Visual Studio Installer | Web Setup Project

Project added to solution.

From File System Editor create project output group by right clicking Web Application Folder | Add | Project Output. From this dialogue select project to deploy, content files and configuration.

Can add further folders, files and assemblies that are not part of project output.

Building Web Setup Project

Not automatically built, must manually select project and build.

Creating Launch Conditions

Defines server requirements for app installation, e.g. check specific version of Windows present.

To access go to View | Editors | Launch Conditions.

Right click Launch Conditions folder and add a new conditions.

Two main branches to Launch Conditions editor:

Typically add item to each of these nodes to require component as part of installation, e.g. to test specific DLL is present create Search Condition under Search Target Machine and store result of search in a property, then create Launch Condition that uses the search conditions property, if property not set then specify error message to display.

Add Simple Search Condition

Right click Search Target Machine and choose from:

Add Simple Launch Condition

Right click Launch Conditions and select Add Launch Condition.

Access Properties window to configure launch condition.

Can set Condition property to match the Property value of a search, or specify different condition entirely. Provide URL in InstallUrl property to resolve launch condition. Set Message property to display to user when condition is not met.

The Condition property can be used to check operating system versions, variables, etc. To evaluate environment variables preface with %, e.g.

%HOMEDRIVE = "C:"

Condition can also check installer variables, e.g.

IISVERSION ="#6"

Can combine checks, e.g.

WindowsBuild=2600 AND ServicePackLevel=1

Pre-grouped Launch Conditions

Can create common pre-grouped search and launch conditions.

Right click root node in Launch Conditions editor and choose from:

Writing To Registry

To access go to View | Editors | Registry.

To add nested key need to add each nested key above it to the editor.

Right click key to add setting, select setting type (String, DWORD, etc.) and then provide a name for the value.

Finally set the value property.

By default key not removed during uninstall, must set the DeleteAtUninstall property to true for this to occur.

Adding Custom Setup Pages

To simplify installation configuration can add custom setup wizard pages and prompt user for install information.

Information collected here can then be passed as parameters to custom actions.

To access go to View | Editors | User Interface

Editor shows different setup phases for both standard and administrative users.

To add custom page right click setup phase to which you want to add and select Add Dialog - n.b. normally added to Start phase under Install mode.

Can customise available dialogue boxes by hiding some controls and displaying different labels.

Adding Custom Actions

Can run in any of four setup phases:

To access go to View | Editors | Custom Actions.

Right click phase to add custom action to then select Add Custom Action.

Select custom.exe or script file to execute at that phase of deployment.

Deploying Web Applications using Web Setup Project

To deploy web application to server use files (usually two) generated by build process:

Deploying Web Applications using Copy Web Tool

Web Setup projects useful if providing website to many users.

If you are responsible for updating site it may be impractical to log on to server, copy over installation and run the msi - especially if frequent updates required.

Copy Web Tool can copy individual files or an entire site.

Select source and remote site and move files between them.

Can use to synchronise files - i.e. copying only changed files and detecting version conflicts, n.b. It cannot perform merges.

Launched from Visual Studio - right click site in solution explorer and choose Copy Web Site.

The Remote Site can be:

Tool will notify of conflicts with remote files, does not provide merging capabilities.

Pre-compiling ASP.NET Websites

ASP.NET Websites (not web applications which are always pre-compiled) pages are compiled the first time they are accessed - performance hit for first visitor. Use pre-compilation to avoid:

Right click web site and select Publishing

Specify publishing location

In Publish Web Site dialogue select appropriate options:

Installing ASP.NET 4 on IIS

Optional Windows Update package available to install .NET 4 onto computers.

After framework installed need to configure IIS to support ASP.NET 4 via the aspnet_regiis.exe - located in root of framework installation.

Downloads