title: MSBuild Item Include (wildcard) not expanding
body: <p>This is very weird.  We've been trying to figure it out for a while, but it really doesn't make any sense.</p>
  
  <p>Our web project imports a targets file that has a target similar to this:</p>
  
  <pre><code>&lt;Target Name="CSSCheckInternal"&gt;
      &lt;ItemGroup&gt;
          &lt;CSSFiles Include="$(MSBuildProjectDirectory)\**\*.css" /&gt;
      &lt;/ItemGroup&gt;
      &lt;CSSChecker Files="@(CSSFiles)" /&gt;
  &lt;/Target&gt;
  </code></pre>
  
  <p>At the moment, one branch is building perfectly, executing the task as desired; but the other branch is failing on the above target.</p>
  
  <p>The failure is because the <code>@(CSSFiles)</code> item, when received by the task, appears not to be expanding into an <code>ITaskItem</code> array.</p>
  
  <p>The task is written as follows (up to the point where I get the FullPath metadata):</p>
  
  <pre><code>public class CSSChecker : Task
  {
      [Required]
      public ITaskItem[] Files
      {
          get;
          set;
      }
  
      public override bool Execute()
      {
          string fullFilePath = null;
          if (Files != null)
          {
              foreach (var item in Files)
              {
                  fullFilePath = item.GetMetadata("FullPath");
                  if(!File.Exists(fullFilePath))
                    throw new InvalidOperationException(
                     string.Format("{0} does not exist", fullFilePath));
  
  
          //rest of the code elided
  </code></pre>
  
  <p>The build that's failing is throwing the <code>InvalidOperationException</code> on the last line there, like this:</p>
  
  <blockquote>
    <p>File does not exist: C:\Code\Project\**\*.css </p>
  </blockquote>
  
  <p>So it would seem that MSBuild, instead of expanding the wildcard in the <code>Include</code> attribute, is merely passing the string over, thus creating only one <code>ITaskItem</code> on the task.</p>
  
  <p>The target folder <strong>does</strong> exist on the disk, and the only difference between the broken project file and the working one is a single file include much earlier in the project file.</p>
  
  <h2>Update</h2>
  
  <p>I <a href="https://twitter.com/RealLordZoltan/status/337885863084171265" rel="noreferrer">asked Sayed Hashimi on twitter</a> (wrote the <a href="https://rads.stackoverflow.com/amzn/click/com/0735626286" rel="noreferrer" rel="nofollow noreferrer">MSBuild book</a>) and through that, tried taking out the <code>**</code> folder wildcard and it's now started working.  This isn't really suitable as the task is meant to be re-usable between projects.  But it would appear to be something to do with this.</p>
  
  <h2>End update</h2>
  
  <p>Please if anyone knows under what situation MSBuild would not correctly expand a wildcard, it would be a great help!</p>