In Visual Studio 2013 we have added a couple of small features for web publishing that I’d like to share with you. Those updates are; how to take your app offline during publishing and how you can update the default file compare option.
App offline support
In Visual Studio when you publish your web application we do not force the remote app to be stopped/restarted. Based on your publishing artifacts your site may end up being restarted (for example you change web.config) but Visual Studio never had a way to take your application offline during a publish operation.
There are a lot of reasons why you may want to take your app offline during publishing. For example you app has files locked which need to be updated, or you need to clear an in-memory cache for changes to take effect. We heard a good amount of feedback from ASP.NET users regarding the lack of this support on our uservoice site. From that suggestion we worked with the Web Deploy team to introduce a new AppOffline rule which enables this.
We also added support for this in Visual Studio 2013 as well. We have not yet created any specific UI for this feature but it’s very easy to enable. Since Visual Studio 2012 web publish profiles are stored as MSBuild files under Properties\PublishProfiles (My Project\PublishProfiles for VB). These files end with a .pubxml extension (not to be confused with .pubxml.user) and have the same name as the Publish Profile in Visual Studio.
Each of these publish profiles contain the settings for that publish profile. You can customize these files to modify the publish process. To enable this find the .pubxml file corresponding to the publish profile you’d like to update. Then add the following element in the PropertyGroup element.
<EnableMSDeployAppOffline>true</EnableMSDeployAppOffline>
So the resulting publish profile will look something like the following.
<?xml version="1.0" encoding="utf-8"?> <Project ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <PropertyGroup> <EnableMSDeployAppOffline>true</EnableMSDeployAppOffline> <WebPublishMethod>MSDeploy</WebPublishMethod> <MSDeployServiceURL>(removed)</MSDeployServiceURL> <DeployIisAppPath>Default Web Site</DeployIisAppPath> <AllowUntrustedCertificate>True</AllowUntrustedCertificate> <SkipExtraFilesOnServer>True</SkipExtraFilesOnServer> <DeployAsIisApp>False</DeployAsIisApp> <MSDeployPublishMethod>WMSVC</MSDeployPublishMethod> <UserName>sayedha</UserName> <ExcludeApp_Data>False</ExcludeApp_Data> <_SavePWD>True</_SavePWD> </PropertyGroup> </Project>
After that you can save and close the file. When you publish (either in Visual Studio or the command line) using that profile your app will be taken offline during publishing.
This feature was implemented as a direct result of your feedback so please keep letting us know how we can improve.
Use checksum support
Web Deploy has two methods of determining which files will be synced when a publish operation is performed.
- Use file time stamps
- Use the CRC (Cyclic Redundancy Check) checksum
By default Visual Studio uses the time stamps method. The reason for this is that there is a noticeable performance impact when using the CRC checksum.
In team scenarios, or on build servers, it may make sense for you to use the CRC method instead. Enabling this is very similar to the app offline support. Find the .pubxml file which is associated with your web project and add the following element under the PropertyGroup element.
<MSDeployUseChecksum>true</MSDeployUseChecksum>
After that when you publish using that profile (from Visual Studio or the command line) the CRC checksum method will be used instead of time stamps.
Other ways to apply these settings
If you would like to enable this for multiple project, or multiple profiles it may get a bit cumbersome to modify every .pubxml file. These properties are standard MSBuild properties so there are several different ways you can apply these settings. Below I’ve outlined a few different options, but if these don’t meet your needs there may be additional options.
Set these properties on the command line/build server
When you invoke msbuild.exe you can pass this property in as you would any other MSBuild property. Use the following syntax,
/p:EnableMSDeployAppOffline=true /p:MSDeployUseChecksum=true
Set these properties for every profile in a given project
In this post I suggested that you place the properties directly inside of the .pubxml file. Instead of this you can place this property directly inside your .csproj/.vbproj file. You should place the following PropertyGroup in your project file.
<PropertyGroup> <EnableMSDeployAppOffline>true</EnableMSDeployAppOffline> <MSDeployUseChecksum>true</MSDeployUseChecksum> </PropertyGroup>
Note: This element should be above the Import for Microsoft.WebApplication.targets.
Set these properties for every project on a machine
If you have a build server (or your own dev box) that you’d like to apply these settings for every build you can create an environment variable with the name/value desired.
You can also use the CustomBeforeMicrosoftCommonTargets MSBuild property. I’ve blogged about how you can use this technique in the past.
Sayed Ibrahim Hashimi | http://msbuildbook.com | @SayedIHashimi
0 comments