gpt4 book ai didi

msbuild - 修改 MSBuild ItemGroup 元数据

转载 作者:行者123 更新时间:2023-12-03 01:20:58 25 4
gpt4 key购买 nike

是否可以在声明 ItemGroup 后修改它的元数据。

例如:

  <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>

我希望有一种方法不需要我删除该项目然后重新声明它。

感谢您的回答。瓦卡诺

最佳答案

是的,您可以修改或添加到<ItemGroup>定义后的元数据 (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>

引用:MSDN Library: New Methods for Manipulating Items and Properties (MSBuild)

关于msbuild - 修改 MSBuild ItemGroup 元数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/841913/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com