tags:

views:

35

answers:

2

I would guess it has to be an ITaskItem since it's a vector instead of scalar, I've got the only 2 MsBuild books here on my desk, and I can't find examples of how to pass in an array to a task. I want to do a string array, but I'd like to know the proper way that would work with any primitive type.

How do you pass in an array of string (or int) to a MsBuild task?

A: 

IIRC, msbuild items are always string arrays - that is the only option. So an array of integers would be stored as an array numeric strings.

Brent Arias
so then it'd be an include list of values `<ItemList Include="1,2,3" />`? Msbuild would automatically convert to `int[]` if the custom task asked for `int[]` and was passed `ITaskItem[]` ?
Maslow
+4  A: 

MSBuild tasks can accept ITaskItem, primitives, string or an array of any of those for parameters. You just declare the type in your task and then the values will be converted before passed to the task. If the value cannot convert to the type then an exception will be raised and the build will be stopped.

For example if you have a task which accepts an int[] named Values then you could do.

<Target Name="MyTarget">
    <MyTask Values="1,45,657" />
    <!-- or you can do -->
    <ItemGroup>
        <SomeValues Include="7,54,568,432,79" />
        <MyTask Values="@(Values) />
    </ItemGroup>
</Target>

Both approaches are essentially the same. The other answers stating that all parameters are strings or that you have to use ITaskItem are incorrect.

You said you have two books on MSBuild, then I presume one is my Inside the Microsoft Build Engine book, you should read the chapter on Custom Tasks so that you get a full grasp on these topics. There is a section explaining parameter types specifically.

Sayed Ibrahim Hashimi
+1 thanks for clearing that up. btw, your ItemGroup tag isn't closed, I imagine it was supposed to close after the SomeValues tag, yes?
Maslow
Sorry about that, I typed the answer on my iPad. Fixed now.
Sayed Ibrahim Hashimi