nyxthulhu
nyxthulhu

Reputation: 9752

Git (SSH) in Visual Studio 2015

So with Visual Studio 2015 just being released there is a much more integrated tie-in with git.

However the feature that seems to be lacking is git over SSH. There are various plugins for 2013 that allow this functionality (i.e GitExtensions) but I can't see any with 2015.

GitHub plugin only appears to work with GitHub and not generic git repos.

I'm not looking for an opinion of which is better, only some examples or articles to see if anyone has got Git+SSH on Visual Studio 2015 working.

Upvotes: 44

Views: 29864

Answers (5)

GSBTom
GSBTom

Reputation: 71

Here's some basic instructions for Visual Studio Update 2 and Update 3. See the link in BPas' post for the basic stuff, e.g. you'll need:

  • CMake (I used 3.5.2)
  • libssh2 (I used 1.7.0)
  • libgit2 source (grab the source from VS 2015 as noted in BPas's link)

Build libssh2

  1. I used libssh2 1.7.0. You can use older, but don't as you'll need to fix some build issues in VS2015.
  2. Do the following:

    cd <libssh2 root dir> (e.g. wherever you extracted the source to)
    mkdir build && cd build
    cmake -DCRYPTO_BACKEND=WinCNG -DBUILD_SHARED_LIBS=OFF -DBUILD_TESTING=OFF -DBUILD_EXAMPLES=OFF ..
    
  3. Open the resulting libssh2.sln in the build directory

  4. Set the build type to "Release" (this is important!)
  5. Edit the libssh2 project, and set the calling type to __stdcall (e.g. /Gz)
  6. Rebuild all, if successful, the resulting lib will be in build/src/Release/libssh2.lib

Build libgit2

  1. Do the following:

    cd <libgit2 source dir> (e.g. this is wherever you extracted the libgit2 source you got from VS2015's extensions directory, see BPas' link for details)
    mkdir build && cd build
    cmake -DCMAKE_BUILD_TYPE=Release -DSTDCALL=ON -DSTATIC_CRT=OFF -DUSE_SSH=OFF -DLIBSSH2_FOUND=TRUE -DLIBSSH2_INCLUDE_DIRS=<libssh2 root dir>/include -DLIBSSH2_LIBRARIES=<libssh2 root dir>/build/src/Release/libssh2.lib ..
    
  2. Open the resulting libgit2.sln in the build directory

  3. Set the build type to "Release"
  4. Optional: Patch src/transports/ssh.c to support SSH RSA key authentication, in function request_creds (around line 444):

    if (!t->owner->cred_acquire_cb) {
        no_callback = 1;
    } else {
    

    with:

    if (!t->owner->cred_acquire_cb) {
        if (user) {
            const char *val = NULL;
            val = getenv("USERPROFILE");
            if (val)
            {
                char *szprivfilename = malloc(strlen(val) + 128);
                char *szpubfilename = malloc(strlen(val) + 128);
    
                strcpy(szprivfilename, val);
                strcat(szprivfilename, "/.ssh/id_rsa");
                strcpy(szpubfilename, val);
                strcat(szpubfilename, "/.ssh/id_rsa.pub");
    
                git_cred_ssh_key_new(&cred, user, szpubfilename, szprivfilename, "");
    
                free(szprivfilename);
                free(szpubfilename);
            }
            if (!cred) {
                giterr_set(GITERR_SSH, "git_cred_ssh_key_new failed to initialize SSH credentials");
                return -1;
            }
        }
        else
        {
            no_callback = 1;
        }
    } else {
    

    Note: this patch was grabbed from one the comments in randomswdev's post, seems to work fine from my limited testing.

  5. Rebuild All, output is git2.dll, replace libgit2-msvc.dll in your Visual Studio 2015 extensions directory

Upvotes: 7

user5895940
user5895940

Reputation:

There used to be nonsense here about adding your git to visual studio using the git bash. Even though adding would work, creating commits was also an option but syncing them would still require the git bash. So this would be kinda useless.

Upvotes: 0

Vladimir Koltunov
Vladimir Koltunov

Reputation: 668

Conforming to BPas: for Visual Studio 2015 it is possible to build SSH enabled version. Moreover, i have patch for public/private key auth support:

https://github.com/PROGrand/git2-msvstfs-ssh-patch

Upvotes: 4

BPas
BPas

Reputation: 99

It is possible to enable ssh support by recompiling the GIT library distributed with Visual Studio 2015. The following article describes the required steps:

http://randomswdev.blogspot.it/2015/07/adding-ssh-support-to-visual-studio.html

Upvotes: 3

Edward Thomson
Edward Thomson

Reputation: 78653

No. Visual Studio 2015 (RTM) does not support SSH for Git remotes. This is true even with GitHub repositories using the GitHub plug-in (which - at present - uses the same connection mechanism for Git repositories as any other Git repository using Team Explorer.)

This is regrettable, but there are a handful of reasons why this is not available yet: the short answer is that in our opinion, providing SSH poorly or insecurely is worse than not providing SSH at all, and we would like to be very confident that any SSH implementation we provide is of high-quality.

That said, we are working on it, and making progress. Microsoft is going to begin including OpenSSH in Windows (and is a sponsor of that very fine project). However I cannot make any predictions as to when support might be available.

The GitHub extension is open source, so it's possible that it may be able to use a different connection mechanism and begin supporting SSH before the core Git support in Team Explorer.

Upvotes: 49

Related Questions