views:

418

answers:

0

Hi,

I've created a tfsbuild.proj file that builds a release version of my solution and in it I have created a custom target for BuildNumberOverrideTarget that handles custom versioning. I store the version number in a file location in TFS and the custom task will get the version number, check out the assemblyinfo.cs files, edit the version details, check in and then increment the version number for the next build.

This was all working fine but only if you have let TFS do the very first build before adding the versioning changes to your tfsbuild.proj file, it's as if it relies on the Sources\ directory structure to already exist from an earlier build. So if you decide to branch your source and run a build as is, it will fail with a weird error like:

Target "InitializeWorkspace" skipped. Previously built successfully.
Target "BuildNumberOverrideTarget" in file "e:\tfstemp\TestProject\TestProject MainBranch Release\BuildType\TFSBuild.proj" from project "e:\tfstemp\TestProject\TestProject MainBranch Release\BuildType\TFSBuild.proj":
Task "Message"
  Loading last build number from file "e:\tfstemp\TestProject\TestProject MainBranch Release\BuildType\..\Sources\Version Number\buildnumber.txt"
Done executing task "Message".
Using "Exec" task from assembly "Microsoft.Build.Tasks.v3.5, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a".
Task "Exec"
  Command:
  "C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\PrivateAssemblies\..\tf.exe" get /force /noprompt /overwrite buildnumber.txt
e:\tfstemp\TestProject\TestProject MainBranch Release\BuildType\TFSBuild.proj(472,5): error MSB6003: The specified task executable "cmd.exe" could not be run. The directory name is invalid
Done executing task "Exec" -- FAILED.
Done building target "BuildNumberOverrideTarget" in project "TFSBuild.proj" -- FAILED.
Done Building Project "e:\tfstemp\TestProject\TestProject MainBranch Release\BuildType\TFSBuild.proj" (EndToEndIteration target(s)) -- FAILED.

Build FAILED.

After some research I found the following website, which states that the ordering is not correct if you want to override the build number target. It suggests either respecifying the order of execution or to add the DependsOnTarget to the BuildNumberOverrideTarget.

http://social.msdn.microsoft.com/forums/en-US/tfsbuild/thread/9103c92d-4b03-41d4-9eae-93c78cb6ea3a/

I have tried both suggestions in the post but I just can't seem to get it to run, the build error seems to skip the InitializeWorkspace.

I have had a workaround in place that partially works but we then see errors in branched areas about a workspace not existing. Our workaround was to make the directory structure in the BuildNumberOverrideTarget with the following edits to the tfsbuild.proj file:

<Target Name="BuildNumberOverrideTarget">
    <!-- Create a custom build number, matching the assembly version -->
    <Message Text="Loading last build number from file &quot;$(MSBuildProjectDirectory)\..\Sources\Version Number\buildnumber.txt&quot;" />

    <!--need to ensure that the sources folder exists-->
    <PropertyGroup>
      <SourcesDirectory>$(MSBuildProjectDirectory)\..\Sources\Version Number</SourcesDirectory>
    </PropertyGroup>
    <MakeDir Directories="$(SourcesDirectory)"/>

    <Exec Command="$(TF) get /force /noprompt /overwrite buildnumber.txt"
          WorkingDirectory="$(MSBuildProjectDirectory)\..\Sources\Version Number\">
    </Exec>

    <Exec Command="$(TF) checkout buildnumber.txt"
      WorkingDirectory="$(MSBuildProjectDirectory)\..\Sources\Version Number\" IgnoreExitCode="true">
    </Exec>
  ... rest omitted to keep short...
</Target>

Is there a way that I can force msbuild when it runs to automatically get the entire source structure before attempting to run any of my custom targets? We're doing a release build and I don't like the idea that maybe it is trying to cache old versions of files and folder structures.

Many thanks,

Emma