Thursday, October 25, 2007

AfterCompile vs AfterCompileSolution

I ran into something with Team Build 2008 that burnt me up for pretty much a whole day. I was using the AfterCompileSolution target (as I saw suggested) to run the building of our setup projects (because MSBuild doesn't support setup projects - how can an open source setup project engine - wix - support MSBuild and MS does support them is beyond me). Anyway, I am also using the AssemblyInfoTask to increment our version numbers. So the $(MaxAssemblyVersion) is always blank. Even though I went into the blah.blah.Versioning.targets and spit it out there and it gives me the 5.0.0.10 I am expecting. So, WTF.

Dunno, but apparently something is out of scope, so if I go back to "AfterCompile" instead of "AfterCompileSolution" then it's back, but now $(Platform) is gone.

????

<Target Name="AfterCompile">

<DevEnv TeamFoundationServerUrl="$(TeamFoundationServerUrl)"
BuildUri="$(BuildUri)"
Solution="$(Solution)"
SolutionConfiguration="Setup"
SolutionPlatform="Any CPU"
Target="Build"
Version="9" />


<WorkspaceItemConverterTask
TeamFoundationServerUrl="$(TeamFoundationServerUrl)"
BuildUri="$(BuildUri)"
WorkspaceName="$(WorkspaceName)"
WorkspaceOwner="$(WorkspaceOwner)"
ServerItems="$/Trimble.MobileSolutions/current">
<Output TaskParameter="LocalItems" ItemName="LocalDirectory" />
</WorkspaceItemConverterTask>

<Exec WorkingDirectory="$(SolutionRoot)"
Command="$(TF) checkin /comment:"Auto-Build: Version Update" /noprompt /override:"Auto-Build: Version Update $(MaxAssemblyVersion)" /recursive $(AssemblyInfoSpec)"
ContinueOnError="true" />

<PropertyGroup>
<LocalDirectoryAsProperty>@(LocalDirectory->'%(FullPath)')</LocalDirectoryAsProperty>
</PropertyGroup>


<CreateItem Include="$(LocalDirectoryAsProperty)\**\product\setup\**\*.msi">
<Output TaskParameter="Include" ItemName="MsiFiles"/>
</CreateItem>

<!--<Copy SourceFiles="@(MsiFiles)" DestinationFolder="$(DropLocation)\xx.$(MaxAssemblyVersion).xx" />-->
<Copy SourceFiles="@(MsiFiles)" DestinationFolder="$(DropLocation)\$(MaxAssemblyVersion)\%(FilesToArchive.RecursiveDir)"/>
<!--<Copy SourceFiles="@(MsiFiles)" DestinationFolder="$(DropLocation)\$(MaxAssemblyVersion)\%(RecursiveDir)" />-->


</Target>

3 comments:

Anonymous said...

Aaron Hallberg's response (got from http://forums.microsoft.com/msdn/ShowPost.aspx?PostID=2332262&SiteID=1&pageid=0#2332262)

The CompileConfiguration and CompileSolution targets (and their overridable Before/After dependencies) are executed via a recursive call to TfsBuild.proj using the MSBuild task - this is why the MaxAssemblyVersion property, which is dynamically generated by the AssemblyInfo task, is out of scope and unavailable in the AfterCompileSolution target. Similarly, these recursive calls to TfsBuild.proj set the $(Configuration), $(Platform), and $(Solution) properties to the currently building configuration, platform, and solution. Back in the "main" scope, all you have access to are the SolutionToBuild item group (the list of solutions) and the ConfigurationToBuild item group (the list of configurations).



Your best bet here might be to modify the assembly info task logic a bit such that it executes as a dependency of CoreCompileSolution rather than CoreCompile - this way you would have access to all the variables you need in the same scope. See my blog post here for more info on how the assembly info task and the Microsoft.VersionNumber.targets work. I would recommend the following change to your logic:

After the Import of Microsoft.VersionNumber.targets, add the following property group that will insert the assembly info task as a dependency of CoreCompileSolution:
[PropertyGroup]

[CoreCompileSolutionDependsOn]

$(CoreCompileSolutionDependsOn);

UpdateAssemblyInfoFiles

[/CoreCompileSolutionDependsOn]

[/PropertyGroup]

Move your AssemblyInfoFiles item group creation into the BeforeCompileSolution target. This way, during CoreCompile this item group will be empty and the AssemblyInfo task will not attempt to update anything during CoreCompile (and instead will wait until CoreCompileSolution).
Hope this helps.

Anonymous said...

Are you into roman showers?

Anonymous said...

There is a far better solution here: http://halflife2.zoy.org