SourceTree Custom Action – Open Solution

Day to day I find myself using Git natively as well as Atlassian’s SourceTree Git client. Keen to ever ease my life with SourceTree I’ve previously written custom actions to open the associated FogBugz case to a commit as well as another custom action to update all or certain NuGet packages for a repository.

Following on from this I have now created another custom action which I wanted to share that allows me to open solution files by simply right clicking on the repository and choosing my new custom action.

The Script

As you can see from the below script this is accomplished extremely easy, in fact in a single line of PowerShell which takes a single input parameter called ‘Repo’.

If copying and pasting isn’t your game then you can also find the script in my PowerShell Tools repository on GitHub along with my previous creations.

########################################################################

# Created By Ashley Poole - http://www.ashleypoole.co.uk               #

# Opens solution file(s) within a specified repository                 #

# SourceTree_OpenSolutions.ps1                                         #

########################################################################


Param(
    [string]
    $Repo
)

# Get and open solution files

Get-ChildItem $Repo -Recurse -Filter '*.sln' | Select { Start $_.FullName }

Setup

Setting the script as a custom action up in SourceTree is also extremely easy. Below is a screenshot of the options you need in order to get the custom action setup. Simply replace ‘C:\scripts...’ with the location of where you have saved the script.

SourceTree Create Custom Action

Usage

Once you have the custom action setup then it can be accessed by right clicking on the repository or a commit and choosing the new custom action called ‘Open Solution’ from within the ‘Custom Actions’ menu.

The solution files if found will then be opened in the default program associated with the file extension.

Right click open solution custom action

Posted in Programming with : Git