MSBuild: Choosing right Target-Inputs for resource-packaging
===

I have written a custom MSBuild-script that is capable of packing resources into zip-files based on the resources type. A resource is a Visual-Studio 2010 Item with a custom Item-name. The custom Item-names that I am using are defined in my custom MSBuild-script as the following example shows:

    <ItemGroup>
      <AvailableItemName Include="AudioResource"/>
      <AvailableItemName Include="ConfigResource"/>
      <AvailableItemName Include="GraphicResource"/>
    </ItemGroup>

Visual-Studio 2010 allows to choose those custom Item-names as values for the 'Build Action' property of an Item in the Project. This way it is possible to mark Items as Resources.

For each Item-name there is a Target that packs all resources with this Item-name into a single Zip-file, using the MSBuild Communitytasks Zip-Task. For example:

    <Target 
     Name="PackConfigResources"
     AfterTargets="AfterBuild"
     Inputs="@(ConfigResource);$(ProjectPath)"
     Outputs="$(OutDir)resources\config.zip">
      
        <MSBuild.Community.Tasks.Zip
          Files="@(ConfigResource)"
          ZipFileName="$(OutDir)resources\config.zip"
          ZipLevel="6"
          Flatten="true" />
      
    </Target>

This script works as expected, but the problem is to recognize if a zip-file needs to be repacked. For example when a new Resource is added or when the Item-name of a resource changes from 'AudioResource' to 'ConfigResource', what should cause the config.zip as well as audio.zip to be repacked.

The only solution I found was adding $(ProjectPath) (path of the .csproj file) to each Targets Inputs-attribute, so it is recognized if the project-configuration changes, what might indicate that the Item-name of a Resource-item has changed.

This causes all zip-files to be recreated even if project-configuration changes were made that should have no impact on the packing of resources into zip-files.

Does anyone have an Idea how I could solve this problem to avoid unnecessary repacking of my zip-files? How could I detect if a zip-file should be recreated? It seems that the number of items that are Inputs to a target don't have any effect on the decision if the target should be called or not. Any help is appreciated.

Greetings and thanks in advance, Unic1988