Is it possible to modify a ItemGroup's metadata after it is declared.
For Example:
<ItemGroup> <SolutionToBuild Include="$(BuildProjectFolderPath)\MySolution.sln"> <Targets></Targets> <Properties></Properties> </SolutionToBuild> </ItemGroup> <Target Name="BuildNumberOverrideTarget"> <!--Code to get the version number from a file (removed)--> <!--Begin Pseudo Code--> <CodeToChangeItemGroupMetaData ItemToChange="%(SolutionToBuild.Properties)" Condition ="'%(SolutionToBuild.Identity)' == '$(BuildProjectFolderPath)\MySolution.sln'" NewValue="Version=$(Version)" /> <!--End Pseudo Code--> </Target>
I am hoping there is a way that does not require me to remove the item then re-declare it.
Thanks for any answers. Vaccano
In addition to the generic Item element, ItemGroup allows child elements that represent types of items, such as Reference , ProjectReference , Compile , and others as listed at Common MSBuild project items.
%(Directory) Contains the directory of the item, without the root directory. For example: MyProject\Source\ %(RecursiveDir)
A target element can have both Inputs and Outputs attributes, indicating what items the target expects as input, and what items it produces as output. If all output items are up-to-date, MSBuild skips the target, which significantly improves the build speed. This is called an incremental build of the target.
None - The file is not included in the project output group and is not compiled in the build process. An example is a text file that contains documentation, such as a Readme file. Compile - The file is compiled into the build output. This setting is used for code files.
Yes you can modify or add to an <ItemGroup>
's meta data after it is defined (MSBuild 3.5)
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <!-- Define ItemGroup --> <ItemGroup> <TestItemGroup Include="filename.txt"> <MyMetaData>Test meta data</MyMetaData> </TestItemGroup> <TestItemGroup Include="filename2.txt"> <MyMetaData>Untouched</MyMetaData> </TestItemGroup> </ItemGroup> <Target Name="ModifyTestItemGroup" BeforeTargets="Build"> <!-- Show me--> <Message Text="PRE: %(TestItemGroup.Identity) MyMetaData:%(TestItemGroup.MyMetaData) OtherMetaData:%(TestItemGroup.OtherMetaData)" Importance="high" /> <!-- Now change it - can only do it inside a target --> <ItemGroup> <TestItemGroup Condition="'%(TestItemGroup.MyMetaData)'=='Test meta data' AND 'AnotherCondition'=='AnotherCondition'"> <MyMetaData>Well adjusted</MyMetaData> <OtherMetaData>New meta data</OtherMetaData> </TestItemGroup> </ItemGroup> <!-- Show me the changes --> <Message Text="POST: %(TestItemGroup.Identity) MyMetaData:%(TestItemGroup.MyMetaData) OtherMetaData:%(TestItemGroup.OtherMetaData)" Importance="high" /> </Target> <Target Name="Build" /> </Project>
Reference: MSDN Library: New Methods for Manipulating Items and Properties (MSBuild)
There is a new to modify metadata by using the Update attribute E.g.
<ItemGroup> <Compile Update="somefile.cs"> // or Update="*.designer.cs" <MetadataKey>MetadataValue</MetadataKey> </Compile> </ItemGroup>
More in the MSBuild documentation
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With