Skip to content

Instantly share code, notes, and snippets.

@azyobuzin
Created July 28, 2018 18:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save azyobuzin/573cba467fab015e241bc35f5cb126d5 to your computer and use it in GitHub Desktop.
Save azyobuzin/573cba467fab015e241bc35f5cb126d5 to your computer and use it in GitHub Desktop.
条件に一致する最初の項目を取得しようとしてもうまくいかない例
<?xml version="1.0" encoding="UTF-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"
DefaultTargets="Build">
<ItemGroup>
<FooItem Include="Foo1" Meta="A" />
<FooItem Include="Foo2" Meta="B" />
<FooItem Include="Foo3" Meta="B" />
<FooItem Include="Foo4" Meta="C" />
</ItemGroup>
<Target Name="Build">
<PropertyGroup>
<!-- $(FirstB) はバッチ実行前の値で評価されるので、これはうまくいかない -->
<FirstB Condition="'$(FirstB)' == '' AND '%(FooItem.Meta)' == 'B'">%(FooItem.Identity)</FirstB>
</PropertyGroup>
<!-- 期待した出力 → Foo2 -->
<!-- 実際の出力 → Foo3 -->
<Message Text="First: $(FirstB)" />
</Target>
</Project>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment