16

I work on different projects that use different source control providers. Subversion, Git, TFS, etc...

To work on Subversion, I've installed AnkhSVN. To work on Git, I've installed the Git Source Control Provider To work on TFS, ...well, you get the idea.

The source control information is saved as part of the solution file.

Yet, invariably, when I open a new project, Visual Studio keeps using whatever the last source control provider selected was. It doesn't seem to pick it up from the solution file. I always have to open the Tools > Options dialog to switch providers (which takes FOREVER!)

Is this something I am doing wrong? I would expect Visual Studio to change providers based on the solution that is open.

If this is something Visual Studio simply doesn't do, is there a macro or extension out there that will automatically figure this out?

I can't believe this question hasn't been asked before, but I didn't see any obvious dupes in the StackOverflow list of "Questions that may already have your answer." Which, sadly, seems to point to the answer of "it's just me."

CleverPatrick
  • 9,261
  • 5
  • 63
  • 86
  • [Neither](http://stackoverflow.com/questions/6678239/how-to-quickly-switch-source-control-providers-in-visual-studio-2010) of [these](http://stackoverflow.com/questions/5994009/how-to-configure-visual-studio-to-use-diferent-source-control-providers) helped? – jswolf19 May 28 '12 at 15:14
  • No. The first one doesn't have a real solution (the guy just removed his need for a solution.) And the second one, the answers seem to be "make sure the source control information is in the solution." And, as a I said, it is. – CleverPatrick May 28 '12 at 15:37

3 Answers3

7

The per solution provider binding is, IMO, wrong as the solution can be resident in multiple source control systems. The trick is to load the proper source control provider checking reserved directories in a pre-load solution event of a VS extension. The core code is as it follow:

IVsRegisterScciProvider vsRegisterScciProvider = GetService<IVsRegisterScciProvider>();
vsRegisterScciProvider.RegisterSourceControlProvider(sccProviderGuid);

The full code for such an extension is here. I may release it shortly after a bit of testing as it's very simple, even if it required me a lot of research. I couldn't find anything similar around and it's strange to me as it should be the obious way to do it. The documentation about RegisterSourceControlProvider was also extremely misleading so that may be the reason.

ceztko
  • 14,736
  • 5
  • 58
  • 73
2

Not really an answer but this was too big to put into a comment:

I hate to say "works for me" but, it does in fact work for me. I'm only using AnkhSVN and the TFS client but Visual Studio switches between the two for me depending on the solution I open. So what you're asking for definitely is "support" to work. Perhaps one of the other plug-in providers has an issue?

Have you opened your solution files and confirmed that the source control information is there? It should look like this:

GlobalSection(SubversionScc) = preSolution
    Svn-Managed = True
    Manager = AnkhSVN - Subversion Support for Visual Studio
EndGlobalSection

GlobalSection(TeamFoundationVersionControl) = preSolution
    SccNumberOfProjects = 5
    SccEnterpriseProvider = {4CA58AB2-18FA-4F8D-95D4-32DDF27D184C}
    SccTeamFoundationServer = http://XXXXX:8080/tfs/XXXXX
    SccProjectUniqueName0 = ...
    SccProjectName0 = ...
    SccLocalPath0 = ...
    <etc>
EndGlobalSection

Also, when you open an appropriate solution, what indication are you getting that it's not switching providers? Do you get an error message, or does your project just not appear bound to source control? In particular, my TFS windows stay open and show wierd errors when I open an SVN solution, but the context menu in Solution Explorer does switch over to the correct provider.

Michael Edenfield
  • 28,070
  • 4
  • 86
  • 117
  • I know because, depending on the loaded source control plugin (AnkhSVN, Git) different visual effects will appear (icon overlays that show the state of files, extra tool windows that allow source control operations, etc...) – CleverPatrick May 30 '12 at 19:31
  • The extra windows will not open or close for you automatically -- those are opened/closed based on what was open when you last closed the solution, independent of the SCC provider. But yes, the icons in the solution explorer ought to update automatically. – Michael Edenfield May 30 '12 at 20:11
  • Checked my .sln file, didn't have the GlobalSection for SubversionScc, added it as above, now VS will switch Source Control options for me when I load that solution. – jdcook72 Feb 09 '16 at 00:29
1

Visual Studio definitely supports this. The source code control provider is expected to persist some kind of information to the solution file about which provider it is and which bindings it's using (if necessary -- VSS and TFS use this, I think).

When VS loads the solution, it's supposed to pick up the correct provider.

It appears from your question, and from this question that it's broken in some way.

You may have to write a macro to do this. It's not particularly difficult. You need to hook the SolutionEvents interface. I'm not sure how you'd get to the configured source control provider. Start here.

With all that said, however, it is supposed to work. I'd try disabling all but two plugins and seeing if it's working. What I'm getting at is that maybe one of the providers is throwing an exception during solution load and VS is giving up on the others.

Community
  • 1
  • 1
Roger Lipscombe
  • 89,048
  • 55
  • 235
  • 380
  • As you say SCC bindings persisted in the solution seem to exist but are totally broken. Also it makes no sense as the solution could be resident in different repositories with multitude of RCS systems. My [extension](https://visualstudiogallery.msdn.microsoft.com/d99d30fb-3dbc-45f0-8c91-8c103e11f996) solves the problem in a different way: it detects presence of reserved folders and load the correct SCC provider accordingly. – ceztko Apr 23 '15 at 12:27