locked
TFS2015 vNext Build + PowerShell Customization -- Exception calling Save: TF215070: The build URI is not valid RRS feed

  • Question

  • Was previously using TFS2013 and XAML-based builds. Had created a number of custom tasks for the XAML builds in C#, including one to set the build number programmatically through the TFS .NET Client API libraries (not the REST API).  Have now moved to TFS2015 and trying to move to vNext-based builds.  Trying to convert our C#-based customizations to the new build process by re-coding as PowerShell scripts.  I am trying to use the following script to programmatically set the build number (as we did previously via C#):

    #STEP1: load the TFS assemblies
    [void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.TeamFoundation.Client")
    [void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.TeamFoundation.Build.Common")
    [void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.TeamFoundation.Build.Client")

    #STEP2: get the collection
    $collection=[Microsoft.TeamFoundation.Client.TfsTeamProjectCollectionFactory]::GetTeamProjectCollection($env:SYSTEM_TEAMFOUNDATIONCOLLECTIONURI)

    #STEP3: get the build server
    $buildServer=$collection.GetService([Microsoft.TeamFoundation.Build.Client.IBuildServer])

    #STEP4: get the details for the currently running build
    $buildDetail = $buildServer.GetBuild($env:BUILD_BUILDURI)

    #STEP5: update the build number
    $buildDetail.BuildNumber = "1.2.3.4-MyBuild"

    #STEP6: save the changes to the build details
    $buildDetail.Save()

    Everything seems to work just fine until "STEP6" when I try and save the change made to the "BuildNumber".  When the "Save()" method is called, the following error is generated:

    Exception calling "Save" with "0" argument(s): "TF215070: The build URI vstfs:///Build/Build/40177 is not valid. Make sure that this build exists and has not been deleted.

    As best I can tell, STEP #4 is returning an instance that implements the "Microsoft.TeamFoundation.Build.Client.IBuildDetail" interface (as I expected it would).  Also, clearly the build URI is valid as it is specifically used to load the build information in that same step.  Again, this logic mimics the same logic we use in our C#-based XAML customizations, just re-written under PowerShell.

    Searching the internet, I can find nothing related to this error and cannot figure out why I would be receiving it.  I did find a (much more complex) version of what I am trying to do here: https://github.com/voice4net/build-scripts/blob/master/ApplyVersionFromSourceControl.ps1.  While I haven't tried using this script directly, it appears to be doing basically the same thing and, presumably, worked for its author.

    Is there anyone out there that can help me understand this error, why I am getting it, and--ideally--how to fix it?!

    Thanks in advanced.

    Tuesday, December 12, 2017 1:18 PM

All replies

  • Hi Gladlon,

    Thanks for posting here.

    This forum is about the MSBuild: Discuss the Microsoft build engine aka MSBuild. Topics including: usage of MSBuild, build customization, and MSBuild extensibility via tasks, loggers and hosting.,  as your issue is more related to the TFS, that forum has been locked. So I suggest that you can submit this issue on stackoverfolw with TFS tag. 

    If you have some MSBuild questions, please feel free to contact us. We will try our best to give you a solution.

    Thanks for your understanding and cooperation.


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, December 13, 2017 5:18 AM