MSBuild tasks can accept primitive arrays, but how do you write them to complete a task?

I would suggest that this should be ITaskItem, since this is a vector instead of a scalar, I only have 2 MsBuild books on my table, and I can not find examples of how to pass the array to the task. I want to make a string array, but I would like to know the correct way to work with any primitive type.

How do you pass an array of strings (or int) to the MsBuild task?

+3
source share
2 answers

MSBuild tasks can accept ITaskItem, primitives, a string, or an array of any of the parameters for the parameters. You simply declare the type in your task, and then the values ​​will be converted before passing to the task. If the value cannot be converted to a type, an exception will be thrown and the assembly will stop.

For example, if you have a task that accepts int[]named Values, you could do it.

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

   <MyTask Values="@(SomeValues) />
</Target>

Both approaches are essentially the same. Other answers that all parameters are strings or that you should use ITaskItemare incorrect.

, MSBuild, , - Microsoft Build Engine, Custom Tasks, . , .

+10

IIRC, msbuild - . , .

0

Source: https://habr.com/ru/post/1769422/


All Articles