在MSBuild中传递变量的不同方法


78

我对MS Build还是比较陌生,并且一直在审查Visual Studio附带的许多内置目标文件。我已经看到变量通过几种不同的方式传递,并且不确定它们之间的区别:

$(...)
@(...)
%(...)

Answers:


96
  • $(...)用于访问Property值(有关Property元素的更多信息)

    <PropertyGroup>
      <Configuration>Debug</Configuration>
    </PropertyGroup>
    
    <Message Text="Configuration = $(Configuration)"/>
    
  • @(...)用于访问Item值(有关Item元素的更多信息)

    <ItemGroup>
      <Reference Include="System.Data"/>
      <Reference Include="System.Web.*"/>
    </ItemGroup>
    
    <Message Text="References = @(Reference)"/>
    
  • %(...)用于获取Item Metadata值(有关项目元数据的更多信息)。它也用于批处理

    <ItemGroup>
      <Compile Include="Account\ChangePassword.aspx.cs">
        <DependentUpon>ChangePassword.aspx</DependentUpon>
        <SubType>ASPXCodeBehind</SubType>
      <Compile/>
    </ItemGroup>
    
    <Message Text="Element @(Compile) of subtype %(SubType) and depend of %(DependentUpon)"/>
    


By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.