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