English 中文(简体)
TFS build 2008 - BuildNumberOverrideTarget DependsOn not executing in correct order for initial build
原标题:
  • 时间:2009-11-19 11:48:26
  •  标签:
  • tfsbuild

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:	fstempTestProjectTestProject MainBranch ReleaseBuildTypeTFSBuild.proj" from project "e:	fstempTestProjectTestProject MainBranch ReleaseBuildTypeTFSBuild.proj":
Task "Message"
  Loading last build number from file "e:	fstempTestProjectTestProject MainBranch ReleaseBuildType..SourcesVersion Numberuildnumber.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 FilesMicrosoft Visual Studio 9.0Common7IDEPrivateAssemblies..	f.exe" get /force /noprompt /overwrite buildnumber.txt
e:	fstempTestProjectTestProject MainBranch ReleaseBuildTypeTFSBuild.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:	fstempTestProjectTestProject MainBranch ReleaseBuildTypeTFSBuild.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)..SourcesVersion Numberuildnumber.txt&quot;" />

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

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

    <Exec Command="$(TF) checkout buildnumber.txt"
      WorkingDirectory="$(MSBuildProjectDirectory)..SourcesVersion 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

问题回答

I m not sure if this works in TFS 2008, but I was able to solve this problem in TFS 2010 by setting the following dependencies:

<Target Name="BuildNumberOverrideTarget" DependsOnTargets="CoreInitializeWorkspace;CoreCleanAll;CoreGet">

You need all 3 dependencies:

  • CoreInitializeWorkspace just creates the workspace, but does not get any files
  • CoreGet gets the files, which is what we want
  • CoreCleanAll is for cleaning out the old code from previous builds. If we don t depend on it, then it will run after CoreGet, and delete all the code we ve just checked out, then the build will fail because it has no code to compile :-)




相关问题
What is the variable signifying the TFS project name?

I am creating a Team Foundation Server (TFS) 2008 build agent for a project of mine. For the working directory, we don t use the default $(Temp)$(BuildDefinitionPath). Instead of Temp, we use a ...

TFS 2008 Build Release Note Like Report

I would like to get some visibility of what changes have gone into our TFS build. Is there some way of finding out all of the resolved work items that have gone into the last X number of builds up to ...

Building select projects only with Team Foundation Build

I’m trying to set up Team Foundation Build and so far it’s running ok with builds, tests and code analysis. My problem is, that I can’t figure out how to build just a subset of the projects included ...

Team Foundation Build (2008) minus the .sln files?

Setting up a new team build in tfs build 2008, you re forced to select a .sln file for your build definition. I ve read through Microsoft.TeamFoundation.Build.Targets, and from what I understand, all ...

Deploy web applications and windows services using TFS 2010

Just went from TFS 2008 to 2010 at a client site and now wondering what happened to the TFSBuild.proj files from the TeamBuildTypes folder. I ve already got the builds and drops working and now I need ...

TFSBuild.Proj and Manual SQL Server Work Help?

Using the VS 2008 GDR update, I have created a database project. I have created a SQL Server deployment package. I have created a database unit test. Using some wizards, the stuff got into my ...

热门标签