3

We just transitioned from using TFS to using Git as our VCS. We are connected to Git and can check-in and such with ease.

But we have a Visual Studio extension that needs to be rewritten for Git. Using TFS programmatically was rather straight-forward, but I can't get anything working with Git. The Microsoft docs are either wrong or I'm doing it wrong. For example, to get a reference to a Git repository, use TfsGitRepository and you get that via TeamFoundationGitRepositoryService. That (supposedly) exists in the Microsoft.TeamFoundation.Git.Server namespace. But when trying to add a reference, Visual Studio claims that namespace doesn't exist; only Microsoft.TeamFoundation.Git.Controls does.

Does anyone know of some reliable documentation for using Git via Visual Studio? Or how to do it?

EDIT

We are using Visual Studio 2015

Frecklefoot
  • 1,660
  • 2
  • 21
  • 52
  • Which Visual Studio? VS 15 (which will drop libgit2) or 2015? See http://stackoverflow.com/a/40059664/6309 – VonC Oct 26 '16 at 17:50
  • Have you checked https://www.visualstudio.com/en-us/docs/integrate/extensions/overview ? – Sergei G Oct 26 '16 at 18:07
  • 1
    Git.Server only exists in the TFS server api, not in the client API. For local client access you're limited to using LibGitSharp or wrapping git.exe directly. – jessehouwing Oct 26 '16 at 18:09
  • @VonC: Sorry, I guess I should've mentioned I'm using VS2015. – Frecklefoot Oct 26 '16 at 20:44
  • @Ypsilon IV: Yes, I read that, but probably just skimmed it. I had dozens of things I was reading, trying to get info. – Frecklefoot Oct 26 '16 at 20:44

1 Answers1

3

The namespace you mentioned is on the TFS server API. It's not available in the TFS Client Object Model. To work with git locally you're going to make sure you have a local clone and then you can talk to it using either LibGit2 (unmanaged), LibGitSharp (Managed) or by invoking and parsing git.exe directly.

Visual Studio doesn't ship with it's own object model for accessing Git, it really depends on these standard open source libraries. Visual Studio up to 2015 ships with a version of LibGitSharp. The next version of Visual Studio (out soon) ships with a new approach to accessing git repositories and wraps git.exe, performing actions against git out-of-process. A wrapper can be found in the Team Explorer extension folder, but I'm not sure on the support levels available on those assemblies:

C:\Program Files (x86)\Microsoft Visual Studio\VS15Preview\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer

If you need to check the available git repositories on the TFS server, you should use the REST api to query the available repo's, then drop to cloning a local git repository after fetching the right repository to clone.

jessehouwing
  • 106,458
  • 22
  • 256
  • 341