Using MSBuild to deploy visual studio 2005 web applications (2)

October 4, 2007 16:38 by Rob

In my previous post I rambled about a bug in the Web Application .targets file. I found an easier solution which does not involve patching any existing files.

The solution is to add the dependency projects to the msbuild target list like so:

msbuild /t:ResolveAssemblyReferences;_CopyWebApplication
     /p:OutDir=..\Drop\bin\ /p:WebProjectOutputDir=..\Drop\

Wow. Life CAN be easy.

Update: Even more so, it is better to use ResolveReferences, which also copies any project assembly references you have in your project.

 Update 2: You actually need to add a 'bin' directory to the OutDir folder. 


Currently rated 4.0 by 5 people

  • Currently 4/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Life's simple if you can analyse its complexity

October 1, 2007 15:29 by Rob

In my search for MSBuild tooling and software complexity analysis, I found the following tool: CCM 

It is a very simple and fast commandline tool. More info later on.


Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Using MSBuild to deploy visual studio 2005 web applications

September 20, 2007 20:48 by Rob

Note: Please check out this update for an easier solution.

Today was cool. I managed to get my first continuous build server online at work using CruiseControl.net. I was cool, up to the point when I wanted to deploy the application nice and clean.

After a lot of googling, I found out that Visual Studio internally uses a .targets file to deploy web applications. It is (by default) referenced in your .csproj file of your web application so you don't have to add it to your solution file (which fortunately IS a msbuild .targets file with just another name). The target file is located here in C:\Program Files\MSBuild\Microsoft\VisualStudio\v8.0\WebApplications. You don't need to install Visual Studio on your build server, you just need to copy the MSBuild directory to the program files folder of your build server. You will however need to install the 2.0 SDK on the build server. it includes a hidden target named '_CopyWebApplication' which you can call.  Thanks to links here and here.

To deploy your web application, just enter the following commandline with your current directory set to the project directory:

msbuild /t:_CopyWebApplication

Unfortunately, this is not sufficient, because the build file detects if the output directory is the same as the current directory:

<Target Name="_CopyWebApplication" Condition="'$(OutDir)' != '$(OutputPath)'">

This problem is easily solved:

msbuild /t:_CopyWebApplication /property:OutDir=..\Drop\ /property:WebProjectOutputDir=..\Drop\

Which will effectually copy all the files in the directory ..\Drop\ and remove the added _PublishedWebsites path, 

but Alas! There is a 'problem' with this solution because references DLL's are not being copied over. I did a lot of googling again and i managed to solve it.

You need to change the line to:

<Target Name="_CopyWebApplication" Condition="'$(OutDir)' != '$(OutputPath)'" DependsOnTargets="ResolveAssemblyReferences">

By making the _CopyWebApplication dependant on the the ResolveAssemblyReferences target (which is a built-in target), the correct properties @(ReferenceCopyLocalPaths) has been magically filled and all your files will be nicely copied to your drop directory. I guess that this is a nifty bug in the web project build file.

There you have it. All that remains is to add another MSBuild task to your Cruisecontrol.net configuration file that publishes the result. I leave that as an exercise to the interested reader because my dinner is ready.


Currently rated 3.3 by 3 people

  • Currently 3.333333/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5