views:

479

answers:

1

I'm creating a custom ITask for MSBuild which uploads the output files of my build. I'm using a web deployment project to publish my app and hooking in to the AfterBuild target to do my custom work.

If I add a file to my web application, the first time I do a build, my custom task is not recognizing the recently added file. In order for that file to show up in my array of ITaskItems, I have to first do a build with my 'AfterBuild' target removed and then start the build again with my 'AfterBuild' target in place.

Here is what my build file looks like:

<ItemGroup>
    <PublishContent Include="$(OutputPath)\**" />
</ItemGroup>

<Target Name="AfterBuild">
    <UploadTask FilesToPublish="@(PublishContent)" />
</Target>

The list in @(PublishContent) seems to be initialized at the beginning of the build instead of reflecting any changes that might have taken place by the build process itself.

Any ideas?

Thanks

+1  A: 

Your ItemGroup is going to get evaluated when the project file first loads (when you first open Visual Studio or you 'unload' and 'reload' the project in Solution Explorer).

What you probably need is to create an ItemGroup as a task in your 'AfterBuild' target. Example:

<CreateItem Include="$(OutputPath)\**">
      <Output TaskParameter="Include" ItemName="OutputFiles"/>
</CreateItem>

followed by:

<Target Name="AfterBuild">
    <UploadTask FilesToPublish="@(OutputFiles)" />
</Target>
Adam
Thanks very much, that was exactly what I needed!
Colin