Based on this question I've tried the following:
EnvDTE80.DTE2 dte = ServiceProvider.GlobalProvider.GetService(typeof(EnvDTE80.DTE2)) as EnvDTE80.DTE2;
No luck, null object.
But based on this MSDN doc I tried the following.
EnvDTE80.DTE2 dte = (EnvDTE80.DTE2)System.Runtime.InteropServices.Marshal.GetActiveObject("VisualStudio.DTE.12.0");
That worked and gave me the DTE2 object.
From there, I tried the following this questin I've tried the following:
VersionControlExt vce = dte.GetObject("Microsoft.VisualStudio.TeamFoundation.VersionControl.VersionControlExt") as VersionControlExt;
No luck, null object.
One thing to note, is per that last question, it says to use Microsoft.VisualStudio.TeamFoundation.Client
namespace. The problem is, I can't find it. I've even made sure to reference the dll by the same name. I was able to reference all the other name spaces.
Finally, I tried the following from teamfoundation.blogspot.
EnvDTE.IVsExtensibility extensibility = GetService(typeof(EnvDTE.IVsExtensibility)) as EnvDTE.IVsExtensibility;
EnvDTE80.DTE2 dte = extensibility.GetGlobalsObject(null).DTE as EnvDTE80.DTE2;
//Followed by this to get the Version
VersionControlExt vce = dte.GetObject("Microsoft.VisualStudio.TeamFoundation.VersionControl.VersionControlExt") as VersionControlExt;
This worked.
So, while I've managed to get the DTE2 and from it the VersionControlExt, I feel I've entered the land of Cargo Cult programmers and would much prefer to understand why these were all posed as valid ways to get the DTE2 but they all behaved differently.