Different ways to pass variables in MSBuild

  • $(...)is used to access Property value (More info on Property element)

    <PropertyGroup>
      <Configuration>Debug</Configuration>
    </PropertyGroup>
    
    <Message Text="Configuration = $(Configuration)"/>
    
  • @(...) is used to access Item value (More info on Item element)

    <ItemGroup>
      <Reference Include="System.Data"/>
      <Reference Include="System.Web.*"/>
    </ItemGroup>
    
    <Message Text="References = @(Reference)"/>
    
  • %(...) is used to acces Item Metadata value (More info on Item Metadata). It’s also used to do batching.

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

Leave a Comment