Project Description
Here is a quick tip on how to modify your TFS build script to publish an ASP.NET site to an existing IIS server (i.e. development environment).

Sample Code
Assuming you have created your basic TFSBuild.proj file, add this to the bottom of the file (right before the </project> tag):

<!-- This task will be executed after the build is copied to the drop location (i.e. build storage) and
will take care of automating the deployment of the project to an IIS folder
by 'Wagner Danda da Silva'
-->
<Target Name="AfterDropBuild" Condition=" '$(BuildBreak)'!='true' ">

<!-- Let's prepare the copy by setting the drop location (IIS website folder) ** -->
<CreateProperty Value="\\dswebdev\QA\"> <!-- replace this with your IIS folder -->
<Output TaskParameter="Value" PropertyName="MyDropLocation"/>
</CreateProperty>

<!-- The path below is where the sources can be found after building ASP.NET projects, you probably won't need to edit this. -->
<CreateItem Include="$(DropLocation)\$(BuildNumber)\%(ConfigurationToBuild.FlavorToBuild)\_PublishedWebsites\Web\\*">
<Output TaskParameter="Include" ItemName="MyDropFiles"/>
</CreateItem>

<!-- Let's remove any pre-deployed files. This will delete any existing files inside all folder and subfolders of the drop location. I opted not to use the default TFS delete task because that was removing security permission on my folders and messing up with my build. The command below won't do that, will simply delete old files (but it won't remove the folders, so if you deleted a folder on your source code you'll have to manually remove it from the drop location - if you actually care for that :D -->
<Exec Command='del /f /s /q $(MyDropLocation)\*'/>

<!-- Copy the files from the build drop location to the IIS website folder -->
<Exec Command='xcopy /Y /R /E "$(DropLocation)\$(BuildNumber)\%(ConfigurationToBuild.FlavorToBuild)\_PublishedWebsites\Web\." "$(MyDropLocation)\.&quot;' />

</Target>

Troubleshooting
1) You save your changes to the TFSBuild.proj file, requests a new build and you don't see the files published:
- Make sure you CHECKED IN your modified TFSBuild.proj file! If you simply change locally and don't check in then TFS when executing a new build will never 'know' that you actually changed that file! Pretty obvious, eh? :D


About Wagner Danda da Silva (blog: www.wagnerdanda.me)
I'm a technical leader at DapaSoft (www.dapasoft.com), working on amazing projects since Jan 2007. On my spare time I like to ride my Harley-Davidson, play squash and make some noise with my drums!

Last edited Nov 13, 2009 at 9:30 PM by wdanda, version 22