开发者

MSBuild tasks can accept primitive arrays, but how do you write one to pass into the task?

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开发者_JAVA百科 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?


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" />
    </ItemGroup>

   <MyTask Values="@(SomeValues) />
</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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜