Web Application Projects (WAP) are a great feature that has been in the field for a while, but which will progressively appear more and more due to its presence in Visual Studio 2005 SP1.

Recently, I had to automate the deployment of a WAP.

To my surprise, there is not easy way to do it in a clean manner.

Publish Wizard in Visual Studio 2005 is great : It copies only the necessary files.

But How Achieve the same Results with Command Line Scripts ? No so straightforward.

 

Web Deployment Projects (WDP) were the immediate Answer.

Unfortunately, have a limitation of WDP with WAP : the Deployed project contains useless file that should NOT appear in the published location; such as *.csproj, *.csproj.user, *.sln.

Even if you loose the opportunity to precompile the site (remove code in aspx files), merge assemblies, (…) , it appeared to me as a better option not to use WDP.

 

What is the solution then ?

The solution is to use a "Hidden" target of WebApplication Target.

The target file is located at :

C:\Program Files\MSBuild\Microsoft\VisualStudio\v8.0\WebApplications\Microsoft.WebApplication.targets

This file contains the definition of the Target available with WebApplication Project.

_CopyWebApplication enables to copy the WebSite in specific location.

 

 

Yet another limitation comes : referenced Dll within the WAP are not copies in the target Bin directory.

A workaround is to

  1. Compile the site

msbuild WebApplication1.csproj /p:Configuration=Release

  1. Copy all assemblies in the target Bin directory

Robocopy.exe bin\ ..\_PublishedWebsites\WebApplication1\bin\ XF *.dll

  1. Call the _CopyWebApplication target

msbuild WebApplication1.csproj /target:_CopyWebApplication /property:OutDir=..\ /p:Configuration=Release

 

You finaly end up with the compiled site, with all and only what you need.