Deploy AspNET web site on IIS from TFS Build
In the last article of the series, I dealt with Deploying on Azure Web Sites from on-premise TFS, but the very same technique can be used to automatically deploy from a standard TFS Build to a standard Web Site hosted in IIS and not in Azure. For this demo I’ve prepared a VM on azure, but the configuration is the very same if the VM is on-premise or if you use a physical machine to run IIS. The only difference between deploy on Azure Web Site is that we are deploying on a Web site hosted on IIS.
Step 1: Configure IIS for Web Deploy You can find a detailed article here with all the steps needed to configure Web Deploy Publishing, once Microsoft Web Deploy is installed, just create a site, and enable Web Publishing right-clicking on it. If the Deploy menu does not appears, some part of the Web Deploy Publishing service was not installed properly.
Figure 1: Configure Web Deploy Publishing
Configuring a Web Deploy publishing for a web site is just a matter of specifying some information and most of the time everything can be left as default value.
Figure 2: Deploy configuration
This dialog will setup the site to enable MSBuild publishing, it saves a.publishSettings file on the location specified (in this example the desktop). The most important settings is the url for the publishing server connection. Be sure that used port (8172 in this example) is opened in the firewall and that all router are configured to make it available to the machine where the build will be run.
Step 2: Configure the Publish settings file Even if the configuration dialog shown in Figure 2 creates a publishSettings file, it is possible to create such file directly from Visual Studio. This is usually a preferable option because it is possible to customize to support Database Publishing and changing the connection string. Actually creating a publish settings from scratch from Visual Studio is really easy, you just Right Click the web project and choose publish, then choose to create a new publishing profile.
Figure 3: Configure the connection for publishing
The Validate connection button is really useful to verify if everything works correctly, once it is green it is possible to further customize the settings. A most common configuration, when you work with Database Projects, is the ability to configure automatic database schema publishing.
Figure 4: Configure for automatic Database Update and change the connection string used in destination server
Once everything is correctly configured you can close the configuration dialog, save the publish settings and check-in everything in source control. To verify if everything work you can do a Test Publish from Visual Studio, just be aware that the location of the.dacpac file should be changed to be found by the Build Controller (described later in this article)
Step 3: Configure the build This is the most easy step, since it is the very same of Deploying on Azure Web Site from on-premise TFS, I’ve actually cloned a build used for that post, and simply changed the name and credentials of the publish settings file used.
Figure 5: Configure MSBuild Arguments to deploy the site
The whole string is the following one, you are simply asking to MsBuild to publish the site using the AzureVM profile.
/p:DeployOnBuild=true /p:PublishProfile=AzureVM /p:AllowUntrustedCertificate=true /p:UserName=gianmaria.ricci /p:Password=xxxxxxxxx
Clearly, to being able to publish database schema, you should manually change the location of the.dacpac file as described in previous article.
As a final note, always configure the build to index sources using a Symbol Server . If a Symbol Server is configured and there is a bug in production site that is not reproducible dev machines, it is possible to use the Intellitrace standalone collector to collect an intellitrace file, and once the itrace file is loaded in Visual Studio it will automatically download original source files used to compile the version of the site used to generate the trace.
Figure 6: Once symbol server is configured, I can browse the source from intellitrace file
This permits to simply open the intellitrace file offline, navigate through events, and have VS automatically download Source code for you, without even knowing where the solution is located.
Gian Maria.