Observe the following piece of an msbuild script:
<ItemGroup>
<R Include="-Microsoft.Design#CA1000" />
<R Include="-Microsoft.Design#CA1002" />
</ItemGroup>
I want to convert it to
/ruleid:-Microsoft.Design#CA1000 /ruleid:-Microsoft.Design#CA1002
Now, the best I came up with is @(R -> '/ruleid:%(Identity)')
, but this only yields
/ruleid:-Microsoft.Design#CA1000;/ruleid:-Microsoft.Design#CA1002
Note the semi-colon separating the two rules, instead of a space. This is bad, it is not recognized by the fxcop - I need a space there.
Now, this is a simple example, so I could just declare something like this:
<PropertyGroup>
<R>/ruleid:-Microsoft.Design#CA1000 /ruleid:-Microsoft.Design#CA1002</R
</PropertyGroup>
But, I do not like this, because in reality I have many rules I wish to disable and listing all of them like this is something I wish to avoid.
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.
An item group is a collection of products which share similar attributes like color, production, features, or usage. Item groups can also be formed based on the markets in which they're sold or if they're similar in price.
To delimit each item by using a character other than a semicolon, use the syntax @(myType, 'separator')
<ItemGroup>
<R Include="-Microsoft.Design#CA1000" />
<R Include="-Microsoft.Design#CA1002" />
</ItemGroup>
<Target Name="FxcopRulesFlattening">
<!-- Using the syntax @(ItemName, 'Separator')-->
<Message Text="@(R -> '/ruleid:%(Identity)', ' ')"/>
</Target>
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