There is a way that you can do this with minimal modifications to your existing code sample. You can combine the metadata from the ConfigFiles elements and the DatabaseConfig elements into a new "combined" element, and then output this "combined" element.
To combine metadata, use batch target when the batch target is run once for each DatabaseConfig element. You can then call another target to output the combined metadata to get the output you describe. Take a look at my extension of your code sample to find out how this will all work:
<?xml version="1.0" encoding="utf-8"?> <Project DefaultTargets="test" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <ItemGroup> <ConfigFiles Include="*.config" /> <DatabaseConfig Include="ABC"> <Database>DB1</Database> <CsString>Database</CsString> </DatabaseConfig> <DatabaseConfig Include="DEF"> <Database>DB2</Database> <CsString>Logging</CsString> </DatabaseConfig> </ItemGroup> <Target Name="test" DependsOnTargets="test_setup;test_output" > </Target> <Target Name="test_setup" Outputs="%(DatabaseConfig.Identity)"> <PropertyGroup> <CurrentDb>%(DatabaseConfig.Database)</CurrentDb> </PropertyGroup> <ItemGroup> <CombinedOutput Include=" %(ConfigFiles.FileName)%(ConfigFiles.Extension) $(CurrentDb) " /> </ItemGroup> </Target> <Target Name="test_output"> <Message Text=" %(CombinedOutput.Identity) " /> </Target> </Project>
What happens in the example:
- The
test target now simply serves to invoke two other goals for the job: test_setup and test_output - The target
test_setup unloaded and creates a new CombinedOutput . - The
test_output is called after test_setup to output CombinedOutput metadata.
Exiting test_output :
one.config DB1 two.config DB1 one.config DB2 two.config DB2
source share