Question: When creating MSBuild Items from files using wildcards, such as,

```
<ItemGroup>
  <Scripts>$(ScriptsDirectory)\**\*.sql</Scripts>
</ItemGroup>

```

the files *seem* to always be sorted alphabetically by path. 

However, is this sort order guaranteed - can I rely on it?

Answer: 
Yes, MSBuild will always sort alphabetically by path, in order to guarantee repeatability. (This is covered in my new book, "MSBuild Trickery")
Some time back I came across an [oddity](http://www.fishofprey.com/2011/04/msbuild-sort-itemgroup.html) transitioning from Visual Studio 2008 to 2010 with the ordering of an ItemGroup that was creating using a wildcard. File names that started with an underscore character '\_' went from being first in the results to last.

At the time I resolved this using the [MSBuild Extension Pack](http://www.msbuildextensionpack.com/). This provides a TaskAction to explicitly sort an ItemGroup.

E.g.

```
<!-- Sort an ItemGroup alphabetically -->  
<MSBuild.ExtensionPack.Framework.MsBuildHelper TaskAction="Sort" InputItems1="@(MainDataFiles)">  
    <Output TaskParameter="OutputItems" ItemName="sorted"/>  
</MSBuild.ExtensionPack.Framework.MsBuildHelper>  
<Message Text="Sorted Items: %(sorted.Identity)"/> 

```