CreateItem与ItemGroup [英] CreateItem vs ItemGroup

查看:163
本文介绍了CreateItem与ItemGroup的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在这样的目标内部创建项目有什么区别?

What is the difference between creating an item inside a target like this:

<Target Name="DoStuff">
    <CreateItem Include="@(IntermediateAssembly)" >
        <Output TaskParameter="Include" ItemName="FileWrites"/>
    </CreateItem>
</Target>

并这样:

<Target Name="DoStuff">
    <ItemGroup>
        <FileWrites Include="@(IntermediateAssembly)" />
    </ItemGroup>
</Target>

您何时会使用其中一个?为什么?

When would you use one or the other and why?

推荐答案

在MSBuild 3.5之前的版本中,您无法在目标内部定义属性或项(例如在第二个示例中).因此,改用了一个任务(CreateItem和CreateProperty)

In versions of MSBuild prior to 3.5 you could not define properties or items inside of targets (like in your second example). So a task was used instead (CreateItem and CreateProperty)

如果您正在使用ToolsVersion 3.5,则不再需要使用CreateItem(尽管您仍然可以选择使用).

If you are using ToolsVersion 3.5 then you don't need to use CreateItem anymore (though you still can if you prefer).

最后,他们都创建了具有相同范围的相同项目.使用第二种语法更具可读性,并且设置自定义元数据要容易得多(我认为).

In the end they both create the item the same, with the same scope. Using the second syntax is more readable and setting up custom meta data is much easier (in my opinion).

注意:.Build 3.5随MSBuild 3.5一起安装.尽管您需要在MSBuild文件的Project标记中定义ToolsVersion="3.5"才能使用3.5功能.

NOTE: The 3.5 version of MSBuild is installed with .NET 3.5. Though you need to define ToolsVersion="3.5" in the Project tag of your MSBuild file to use 3.5 features.

如果您想知道,我从我非常喜欢的书Inside the Microsoft® Build Engine: Using MSBuild and Team Foundation Build中获得了大部分信息(但没有任何关联).

In case you are wondering, I got most of this info from the book Inside the Microsoft® Build Engine: Using MSBuild and Team Foundation Build which I really liked (but am not affiliated with in any way).

这篇关于CreateItem与ItemGroup的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆