Friday, November 20, 2009

Visual Studio macro for opening file from unit test folder

My test creates log file in current test execution folder dir. And sometime I need to open that file to see content. So, I made macro in visual studio for that:

Public Sub OpenLog()
Dim solutionPath As String
Dim solutionDir As String
Dim dirInSolution As String()

solutionPath = DTE.Solution.FullName
solutionDir = Path.GetDirectoryName(solutionPath)
solutionPath = solutionDir + "\TestResults"
dirInSolution = Directory.GetDirectories(solutionPath)

Dim lastTestDir As String
Dim currentDT As Date

For Each currentDir As String In dirInSolution
Dim ct As Date
ct = Directory.GetCreationTime(currentDir)
If (ct > currentDT) Then
currentDT = ct
lastTestDir = currentDir
End If

' we have dir name
' open log file from that dir
Dim finalPath = lastTestDir + "\Out\trace.log"
DTE.ItemOperations.OpenFile(finalPath, ViewKind:=EnvDTE.Constants.vsViewKindTextView).Activate()
End Sub

1 comment:

Anonymous said...

nice post. thanks.