views:

530

answers:

2

As part of my TFS (2008) build I want to manually copy the binaries and Views of an ASP.NET MVC project to a number of different locations. All existing binaries and views are copied successfully. Unfortunately, however, any newly added views are ignored during their first build. If I then start another build, they are included.

Here is a snippet of the additions I have made to TFSBuild.proj...

<ItemGroup>
  <BinaryFiles Include="$(BinariesRoot)\Debug\_PublishedWebsites\SiteName\bin\*.*" />
  <ViewFiles Include="$(BinariesRoot)\Debug\_PublishedWebsites\SiteName\Views\**\*.aspx" />
  <ViewFiles Include="$(BinariesRoot)\Debug\_PublishedWebsites\SiteName\Views\**\*.ascx" />
</ItemGroup>

<Target Name="AfterDropBuild">
  <Message Text="Starting deployment copy..." />
  <Copy SourceFiles="@(BinaryFiles)" DestinationFolder="T:\BuildWebSiteHosting\WebSite\bin\" ContinueOnError="false" />
  <Copy SourceFiles="@(ViewFiles)" DestinationFolder="T:\BuildWebSiteHosting\WebSite\Views\%(RecursiveDir)" ContinueOnError="false" />
  <Message Text="Deployment copy completed." />
</Target>

I suspect that the list of files to copy is being built too early. Should I be using "AfterDropBuild" or is their a better target name?

+2  A: 

I managed to solve this one myself (it was very helpful just asking the question and organising my own thoughts!). My suspicions that the lists of files were being built too soon were correct. By placing the ItemGroup inside the Target element you can specify when it is evaluated.

Corrected snippet is:

<Target Name="AfterDropBuild">
  <ItemGroup>
    <BinaryFiles Include="$(BinariesRoot)\Debug\_PublishedWebsites\SiteName\bin\*.*" />
    <ViewFiles Include="$(BinariesRoot)\Debug\_PublishedWebsites\SiteName\Views\**\*.aspx" />
    <ViewFiles Include="$(BinariesRoot)\Debug\_PublishedWebsites\SiteName\Views\**\*.ascx" />
  </ItemGroup>

  <Message Text="Starting deployment copy..." />
  <Copy SourceFiles="@(BinaryFiles)" DestinationFolder="T:\BuildWebSiteHosting\WebSite\bin\" ContinueOnError="false" />
  <Copy SourceFiles="@(ViewFiles)" DestinationFolder="T:\BuildWebSiteHosting\WebSite\Views\%(RecursiveDir)" ContinueOnError="false" />
  <Message Text="Deployment copy completed." />
</Target>
Chris Arnold
A: 

Wow, this post is a bit dated but this is the exact problem I was running into with our "continuous deployment". Edited files would get deployed but not new files that were added. This fix worked perfectly. Thank you!.

Matt D