Update: Part 2, Web Application Projects.
The thing I like about Web Deployment Projects is the easy configuration of things like compilation (I like to compile to a single assembly), configuration section replacement (so, so much easier than setting this up in NAnt) and deployment. I also really like Team Builds, because they’re so easy to set up (compared to NAnt and CruiseControl.Net). But they don’t have the customisation features of Web Development Projects that I mentioned above. Plus the deployment option in a Team Build is absolutely useless to me, because it deploys the web project to a different folder every time. So I need a way to combine the two configuration features plus make sure the website is deployed to a specific folder on our development web server.
Initially I thought this would be really easy, in fact I expected that the Visual Studio team had specifically designed Team Build and WDPs to compliment each other. Ummmmm not exactly, it seems. I had loads of trouble getting the two to work together, with loads of builds failing due to stupid problems… usually due to the WDP losing its context and building the wrong stuff.
The best guide I found on the subject is this one. It explains that ASP.Net Websites and Web Application Projects are treated differently by Team Build (not why, just that they are) and that you need to use specific, different platform configurations.
To get my ASP.Net Website project (I haven’t tried Web Application Projects yet) working I created a WDP for it. I specified that it should build under the Release configuration, then checked in my solution. I then created a Team Build which targeted the Release|Mixed Platforms configuration. At that point I ran the team build and happily everything came up green, including the WDP.
To my dismay though, although the Web Deployment Project ran, it wouldn’t copy the build to the folder I specified in the WDP configuration. It just wouldn’t do it, and I have a feeling it’s something like the Team Build overriding the drop folder property that the WDP picks up.
The bottom line is that you need to manually override a build task to perform the copy yourself. This isn’t that difficult, and I’m happy to say it’s a step that I can expect other the other developers I work with to perform without needing to know too much about what’s going on.
So the final step was to modify the Team Build project file slightly. First I added the following property group, just below the closing </ProjectExtensions> element:
<PropertyGroup>
<!-- change this to the name of the Web Deployment Project -->
<BuildFileName>Engelbart2</BuildFileName>
<!-- change this to location where you want the website deployed to -->
<DeployLocation>\\engelbart\wwwroot\projects\tequila\digital playground\buildtest\staged</DeployLocation>
<!-- don't worry about this -->
<WebBinariesLocation>$(SolutionRoot)\..\Binaries\Mixed Platforms\Release\_PublishedWebSites\$(BuildFileName)</WebBinariesLocation>
</PropertyGroup>
Then I added the following below the last </ItemGroup> element (I don’t think it actually matters where you put this):
<!-- deploy the compiled site to where we want it to go -->
<Target Name="AfterCompile">
<MakeDir Directories="$(DeployLocation)" />
<!--<Exec Command="xcopy /y /e '$(WebBinariesLocation)' '$(DeployLocation)'"/>-->
<ItemGroup>
<ProjectSourceFiles Include="$(WebBinariesLocation)\**\*.*"/>
</ItemGroup>
<Copy
SourceFiles="@(ProjectSourceFiles)"
DestinationFiles="@(ProjectSourceFiles->'$(DeployLocation)\%(RecursiveDir)%(Filename)%(Extension)')">
<Output
TaskParameter="CopiedFiles"
ItemName="SuccessfullyCopiedFiles"/>
</Copy>
</Target>
This works because your web deployment project is build as part of the team build into it’s own special folder. So for instance I could have team builds called ‘Development’, ‘Staging’ and ‘Production’, each with special web.config settings which the WDP would handle for me. The output from Team Build will be three websites, each in a distinct folder with the correct configuration. It wouldn’t be difficult to modify the above script to copy three seperate releases.
Hope this clears up some mysteries…..