Showing posts with label TFS. Show all posts
Showing posts with label TFS. Show all posts

Monday, October 3, 2011

Comparing TFS source branch with destination branch

When a TFS branch is not "enhanced" with visualisations, it can be tricky to determine the version of the source branch.

I recently wanted to find all the changes that had been made in a branch, including some tweaks that had been made when the branch action was initially checked in. The most reliable way to do this is to compare the source branch at the revision that the branch was made with the latest code in the branch. To do this, I wanted to use the following command line:

tf folderdiff "$/SourceBranch;RevisionThatBranchWasTakenFrom" $/DestinationBranch

However, I needed a way to determine RevisionThatBranchWasTakenFrom. Since branching in TFS is essentially copying (the metadata of) each file in the source branch to the destination, there is no single concept of the 'revision' of the source branch at the point when the branch was made (in contrast to Subversion). The best I could come up with was to find the most recent changeset in the source branch before the branch was made. To do this, I used the tf merges command on the destination branch, which lists all the files that have been merged into the destination branch. I have made several assumptions, including that there was a single branch into the destination and no subsequent merges:

tf merges $/SourceBranch /r /showall /format:detailed | % {$_ -match '(\d+) ->' | out-null; $Matches[1]} | sort -Descending | select -first 1

This PowerShell one-liner will return the highest revision number of all the branched files, assuming that nothing untoward happens and it can parse the output of tf merges. In our case, I knew that all the changesets in question had four digits, so the string based sort would work fine.

Now that I had the most recent changeset, I could run the command to get the changes:
tf folderdiff "$/SourceBranch;C12345" $/DestinationBranch

Friday, July 1, 2011

TFS/MSBuild error with null character in compiler output

I ran into the following error on the TFS build server, which is building a MicroFocus Cobol.NET program:

MSBUILD : error MSB4015: The build stopped unexpectedly because the "WorkflowCentralLogger" logger failed unexpectedly during shutdown. System.ArgumentException: '.', hexadecimal value 0x00, is an invalid character. at System.Xml.XmlConvert.VerifyCharData(String data, ExceptionType invCharExceptionType, ExceptionType invSurrogateExceptionType) at System.Xml.XmlCharCheckingWriter.WriteString(String text) at System.Xml.XmlWriter.WriteAttributeString(String localName, String value) at Microsoft.TeamFoundation.Build.Client.InformationField.ToXml(XmlWriter writer, String element) at Microsoft.TeamFoundation.Build.Client.Helper.ToXml(XmlWriter writer, String element, InformationField[] array) at Microsoft.TeamFoundation.Build.Client.InformationAddRequest.ToXml(XmlWriter writer, String element) at Microsoft.TeamFoundation.Build.Client.Helper.ToXml(XmlWriter writer, String element, InformationChangeRequest[] array) at Microsoft.TeamFoundation.Build.Client.BuildWebService.UpdateBuildInformation(InformationChangeRequest[] changes)

Based on the stack trace, it looks like there was a problem converting the build output to XML, so it was just a matter of finding the culprit. A quick search through the build output using PowerShell located the offending \0 character (which it is not possible to represent in XML), so I loaded the build log into NotePad++ to confirm:

NUL char in NotePad++

Hopefully this will help anyone else who may run into this issue in TFS.

Wednesday, November 3, 2010

Complex work item queries in TFS

I recently wanted to create a work item query that showed all my work items that are either not closed or I had modified recently. This query provides a useful list of work items for associating with a check-in.

I wanted the query to show:
AssignedTo = @Me AND (State <> Closed OR (State = Closed AND ChangedDate > @Today - 7))

To do this, I needed to use multiple levels of the Group Clauses feature, which is available by selecting more than one clause and right clicking on one of the selected clauses.

The result is below:

Friday, October 29, 2010

Executing a PowerShell script from TFS 2010 workflow

  1. Add an InvokeProcess activity to the workflow.
  2. Set the DisplayName property to something useful for logging and debugging.
  3. Set the FileName property to "powershell.exe"
  4. Set the Arguments like this:
    "-file """ + SourcesDirectory + "\Scripts\SetAssemblyVersions.ps1"" " + MajorVersionNumber.ToString() + " " + MinorVersionNumber.ToString() + " " + BuildDetail.SourceGetVersion.Substring(1) + " " + BuildDetail.BuildNumber.Substring(BuildDetail.BuildNumber.LastIndexOf(".") + 1)
  5. Give names to the standard output and error output streams.
  6. Add a WriteBuildMessage activity under the Handle Standard Output field and set its Message property to the standard output stream defined above.
  7. Add a WriteBuildError activity under the Handle Error Output field and set its Message property to the error output stream defined above.

Tuesday, October 19, 2010

Invalid code coverage item error in MSTest

I ran into the following running unit tests after a build under TFS 2010:

Invalid code coverage item: The pdb file name must contain at least one character.

I had modified the .testsettings file to use relative paths instead of absolute paths, but the build was failing with the above error.

The solution was to edit the .testsettings file to add a pdbFile attribute:

<CodeCoverageItem binaryFile="..\Utilities\%outdir%\Utilities.dll" pdbFile="..\Utilities\%outdir%\Utilities.pdb" instrumentInPlace="true" />

Tuesday, July 13, 2010

Relative paths in .testsettings file

To configure relative code coverage paths in the .testsettings file, you will need to manually edit the xml file. First configure your coverage DLLs using the UI, then open the .testsettings file in a text editor, or in VS using the VS text editor.

Edit the absolute paths to be relative to the location of your testsettings file, and use the %outdir% macro instead of bin\Debug:
..\..\Utilities\%outdir%\Utilities.dll