Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make msbuild ItemGroup items be separated with a space rather than semi-colon?

Tags:

msbuild

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.

like image 657
mark Avatar asked Jun 09 '10 18:06

mark


People also ask

What is ItemGroup in MSBuild?

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.

What is ItemGroup?

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.


1 Answers

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>
like image 126
Julien Hoarau Avatar answered Sep 21 '22 08:09

Julien Hoarau