繁体   English   中英

在MsBuild中,PropertyGroup和ItemGroup之间有什么区别

[英]In MsBuild, what's the difference between PropertyGroup and ItemGroup

我可以编译PropertyGroup引用的.cs文件:

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <PropertyGroup>
        <AssemblyName>MSBuildSample</AssemblyName>
        <OutputPath>Bin\</OutputPath>
        <Compile>helloConfig.cs</Compile>
    </PropertyGroup>

    <Target Name="Build">
        <MakeDir Directories="$(OutputPath)" Condition="!Exists('$(OutputPath)')" />
        <Csc Sources="$(Compile)" OutputAssembly="$(OutputPath)$(AssemblyName).exe"/>
    </Target>        
</Project>

或使用ItemGroup做同样的事情:

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">    
    <ItemGroup>
        <Compile Include="helloConfig.cs" />
    </ItemGroup>

    <PropertyGroup>
        <AssemblyName>MSBuildSample</AssemblyName>
        <OutputPath>Bin\</OutputPath>
    </PropertyGroup>

    <Target Name="Build">
        <MakeDir Directories="$(OutputPath)" Condition="!Exists('$(OutputPath)')" />
        <Csc Sources="@(Compile)" OutputAssembly="$(OutputPath)$(AssemblyName).exe"/>
    </Target>  
</Project>

我知道使用ItemGroup应该是首选方法,但什么时候我应该使用这些属性中的每一个?

将属性组视为单个变量的集合,属性只能包含一个值。

而itemgroup类似于一个数组或集合,它可以包含零个,一个或多个值。 您还可以迭代项目组,这对于您希望针对多个项目执行相同任务时通常很有用。 一个常见的例子是编译许多文件。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM