Checkout, Add, Checkin

Jan 7, 2013 at 5:55 PM

I've got a little MSBuild file I'm working up that will execute from my build process template after a successful build.  The idea is to take the output of the build (binaries) from the drop folder, then check them into TFS (shared binaries, of course).  

I can check out and check in just fine.  What I'm having trouble with is TfsSource TaskAction="Add."  The parameters for this just evade me.  It seems to me that if I check out the binaries from the folder in TFS, then add the files from the drop folder, then check them in, that would do what I need.  Like this:

    <MSBuild.ExtensionPack.VisualStudio.TfsSource TaskAction="Checkout" ItemPath="$(BinaryPath)" Version="2010" WorkingDirectory="$(SolutionRoot)" />
    <MSBuild.ExtensionPack.VisualStudio.TfsSource TaskAction="Add" ItemCol="@(FilesToAdd)" WorkingDirectory="$(SolutionRoot)\Binaries" Version="2010" />
    <MSBuild.ExtensionPack.VisualStudio.TfsSource TaskAction="Checkin" ItemPath="$(BinaryPath)" Version="2010" WorkingDirectory="$(SolutionRoot)" ContinueOnError="true" Comments="Auto-checkin" OverrideText="JR" />

I just get "Exit Code 100. Nothing Succeeded: Unable to determine the workspace. You may be able to correct this by running 'tf workspaces /collection:TeamProjectCollectionUrl'." on the Add action.

$(BinaryPath) is passed in from the build definition to the build template.  
$(SolutionRoot) is the build server's working folder for the build
$(FilesToAdd) is the ItemGroup of all the files from the drop folder

I suspect I don't understand the Add function properly.  Can anyone help?

Jim Roth

Jan 8, 2013 at 3:49 PM

I went with a copy instead of an Add, and have gotten this to work.  However, I've still got a hard-coded path that I need to parameterize in order to make this generic.  

    <!-- Add the files from the drop folder back to TFS and check them in.  -->
    <MSBuild.ExtensionPack.VisualStudio.TfsSource TaskAction="Checkout" ItemPath="$(BinaryPath)" Version="2010" WorkingDirectory="$(SolutionRoot)" />
    <Copy SourceFiles="@(FilesToAdd)" DestinationFolder="$(SolutionRoot)\Sources\Main\MT\_MTDependencies\GCBaseClasses" OverwriteReadOnlyFiles="true"/>
    <MSBuild.ExtensionPack.VisualStudio.TfsSource TaskAction="Checkin" ItemPath="$(BinaryPath)" Version="2010" WorkingDirectory="$(SolutionRoot)" ContinueOnError="true" Comments="Auto-checkin" OverrideText="JR" />

Those little @ and $ symbols are important. :/

Jan 29, 2013 at 7:33 PM

This forum is not very useful, I'm afraid.  

Nonetheless, here's how I solved this problem:

    <!-- Check out the binaries from TFS-->
    <MSBuild.ExtensionPack.VisualStudio.TfsSource TaskAction="Checkout" ItemPath="$(BinaryPath)" Version="2010" WorkingDirectory="$(SolutionRoot)" />
    <!-- Add the files from the drop folder to the Build Agent working folder.  -->
    <Copy SourceFiles="@(FilesToAdd)" DestinationFolder="$(MyAbsolutePathProperty)$(WorkSpacePath)" OverwriteReadOnlyFiles="true"/>
    <!-- Check in the updated binaries to TFS -->
    <Exec Command="$(TF) checkin $(BinaryPath) /comment:"***NO_CI***" /bypass /noprompt /recursive /override:"Auto-Build: Version Update" " WorkingDirectory="$(SolutionRoot)" />

$(BinaryPath) and $(SolutionRoot) are passed in from the calling workflow.  @(FilesToAdd) is the enumeration of the files in the Drop Folder (also passed in from the workflow).  I used the /bypass parameter of the tf.exe command to override the gated builds that would have otherwise been triggered by this check-in.  It's also the reason I didn't use the Extensions checkin command.  As a matter of fact, I could easily have done this whole thing without the extensions altogether.

If anyone wants the whole script, just message me.



Mar 29, 2013 at 3:35 AM
I created a feature request here.
Apr 13, 2013 at 5:24 PM
Marked as answer by mikeFourie on 10/9/2013 at 3:28 PM