- Get the latest code from Source (Un)Safe.
- Clean (delete all bin and obj directories).
- Compile 65 VB.NET 2005 projects individually in dependency order (NOT using a master solution file).
- Copy most of the build output to a common bin directory.
- Run an InstallShield script that packages the files in the common bin directory into an *msi file.
- Copy the resulting *.msi file to a turnover directory.
- Email QA to let them know there is a new build available.
<Target Name="CompileWithStop">
<MSBuild
Projects="@(ProjectReferences)"
Targets="Build"
StopOnFirstFailure="True" />
</Target>
<ItemGroup>
<CompileOutput Include="..\Source\**\bin\**\*.exe" Exclude="..\Source\**\bin\**\*.vshost.exe" />
</ItemGroup>
<Target Name="Copy" >
<Copy SourceFiles="@(CompileOutput)"
DestinationFolder="$(OutputDirectory)"></Copy>
</Target>
And here is the bug: It turns out that all ItemGroups in an MSBuild script are processed BEFORE all Targets! So this means that my CompileOutput item actually is based on the files that were generated by the PREVIOUS build! The insidiously subtle part of this is that builds usually generate the same output, so the script "works" except for the first time new file is added, or the first time after a broken build that didn't generate all of it's output files.
Fortunately there is a solution. The CreateItem task can be used to create an Item within a Target. The MSBuild snippet below fixed my problem:
<Target Name="Copy" >
<CreateItem Include="..\Source\**\bin\**\*.exe" Exclude="..\Source\**\bin\**\*.vshost.exe">
<Output TaskParameter="Include" ItemName="CompileOutput" />
</CreateItem>
<Copy SourceFiles="@(CompileOutput)"
DestinationFolder="$(OutputDirectory)"></Copy>
</Target>
This "feature" is apparently "by design", but it is definitely counter intuitive. I had incorrectly assumed that an ItemGroup was processed when (and only IF) it was referenced...
Here is the reference that solved it for me: http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=390321&SiteID=1
2 comments:
Thanks Eric!! We ran into this problem on Stack Overflow builds -- your fix helped us!
Jeff
You can now use ItemGroup elements in a Target element if you are using MSBuild 3.5 and have ToolsVersion="3.5" as well.
Found this on MSDN reference site for ItemGroup Element(MSBuild) in the community comment section
http://msdn.microsoft.com/en-us/library/646dk05y.aspx
Post a Comment