tags:

views:

46

answers:

2

I'm rather new to MS Build and have been reviewing many of the built in target files that ship with Visual Studio. I have seen variables passed a few different ways and am not quite sure of the differences...

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

Thanks in advance.

+1  A: 

Dollar - $(MyProp): Allows you to reference values specified within PropertyGroups.

At Sign - @(CodeFile): Allows you to reference lists of items specified within ItemGroups.

Percent - %(CodeFile.BatchNum): Allows you to reference batched ItemGroup values using metadata. This is a bit more complicated, so definitely review the documentation for more info.

Take a look at each link for more detailed info on how these are used. Good luck -- hope this helps!

Indolent Code Monkey
+3  A: 
  • $(...)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)"/>
    
madgnome