title: How do I perform the EXEC task in a "loop" with MSBuild ItemGroups?
body: <p>How do I perform the EXEC task in a "loop" with MSBuild ItemGroups?</p>
  
  <p>Instead of repeating this command over and over, like so:</p>
  
  <pre><code>    &lt;Exec ContinueOnError="false" Command="sqlcmd -S $(ServerName) $(SqlServerUser) -d $(DbName) -v TableName=%22account%22 -i data\add_sql_cache.sql -b" /&gt;
      &lt;Exec ContinueOnError="false" Command="sqlcmd -S $(ServerName) $(SqlServerUser) -d $(DbName) -v TableName=%22services%22 -i data\add_sql_cache.sql -b" /&gt;
      &lt;Exec ContinueOnError="false" Command="sqlcmd -S $(ServerName) $(SqlServerUser) -d $(DbName) -v TableName=%22servicesGroup%22 -i data\add_sql_cache.sql -b" /&gt;
      &lt;Exec ContinueOnError="false" Command="sqlcmd -S $(ServerName) $(SqlServerUser) -d $(DbName) -v TableName=%22servicesCategory%22 -i data\add_sql_cache.sql -b" /&gt;
  </code></pre>
  
  <p>I'd rather define an ItemGroup and just execute a "loop".  I've got the ItemGroup down:</p>
  
  <pre><code>&lt;ItemGroup&gt;
      &lt;CachedTables Include="account" /&gt;
      &lt;CachedTables Include="services" /&gt;
      &lt;CachedTables Include="servicesGroup" /&gt;
      &lt;CachedTables Include="servicesCategory" /&gt;
  </code></pre>
  
  <p>But due to MSBuild's amazingly unintuitive syntax, I have no idea how to perform the Exec task in a loop with the ItemGroup above as an input.</p>