SourceTree custom action: Open solution in Visual Studio
A quick guide demonstrating how to set up SourceTree custom actions to search a repository for a Visual Studio Solution File and then open it in Visual Studio.

This blog post will show you how to set up a custom action in SourceTree that will search your repository for a Visual Studio Solution File and then immediately open that file in Visual Studio.

Here is a screenshot showing it in action:

The implementation is actually a very simple Powershell script that searches for solution files and launches the first one it finds:

param ([string] $repository)

if ($repository) {
  $solutionFile = Get-ChildItem -Path $repository -Recurse -Filter *.sln | Select-Object -first 1
  if ($solutionFile) {
    Start-Process $solutionFile.FullName

It also helps to have a batch file to launch the Powershell script:

@echo off
powershell.exe -NoProfile -ExecutionPolicy Bypass -File "%~dp0sourcetree-open-repository.ps1" %1

Setting it up is easy:

  1. Save the Powershell script as sourcetree-open-repository.ps1
  2. Save the batch file as sourcetree-open-repository.cmd
  3. Open SourceTree
  4. Navigate to the Custom Actions menu (Tools -> Options -> Custom Actions)
  5. Create a new action with the following properties (see screenshot below):
    • Menu caption: Open in Visual Studio
    • Script to run: The full path of your batch file, from step 2.
    • Parameters: $REPO

I hope you find this information useful.

Posted by Matthew King on 25 May 2016
Permission is granted to use all code snippets under CC BY-SA 3.0 (just like StackOverflow), or the MIT license - your choice!
If this post helped you out, feel free to shout me a coffee