title: Obtain file sizes in MSBuild script
body: <p>Can I find out the sizes of a set of files from an MSBuild script without writing my own code?</p>
  
  <p>MSBuild itself some metadata on individual items (for example, the last modified time at %(ModifiedTime)
  ), but no sizes. I can't see anything at <a href="http://msbuildextensionpack.com/" rel="nofollow">http://msbuildextensionpack.com/</a>.</p>
  
  <p><strong>Edit:</strong> based on Seva's answer, here's an inline task that returns the total size of an array of items:</p>
  
  <pre><code>&lt;UsingTask TaskName="GetFileSize" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll"&gt;
    &lt;ParameterGroup&gt;
      &lt;Files ParameterType="Microsoft.Build.Framework.ITaskItem[]" Required="true" /&gt;
      &lt;TotalSize ParameterType="System.Int64" Output="true"/&gt;
    &lt;/ParameterGroup&gt;
    &lt;Task&gt;
      &lt;Using Namespace="System.IO"/&gt;
      &lt;Code Type="Fragment" Language="cs"&gt;&lt;![CDATA[
          long l = 0;
          foreach (var item in Files) {
              var fi = new FileInfo(item.ItemSpec);
              l += fi.Length;
          }
          TotalSize = l;
  ]]&gt;&lt;/Code&gt;
    &lt;/Task&gt;
  &lt;/UsingTask&gt;
  </code></pre>