locked
How to make "Add Solution to Source Control" available? RRS feed

  • Question

  • I use Git in VS 2019:


    I have an existing solution.  When I right-click the solution, I do not see the option of adding it to source control:

    You may wonder why the context menu has "Commit...". It is for a library used in this solution that is already under source control.  This library is outside this solution's folder.  I want to add every project in this existing solution to source control.

    Could anyone offer a tip on this?


    Hong



    Wednesday, August 5, 2020 4:04 PM

Answers

  • Hi Hong(MA, USA),

    Version control is a system that records changes to a file or set of files under specific path. After we add files of Library project into source control, the Library project would have one newly created `.git` folder which represents its git system. Now if we import the Library Project which has git system into current solution which is not under source control, VS will recognize the git system of Library project as current solution's git system. (Though actually the git system is only for Library project outside current solution folder)

    To add the solution into source control:

    1.We need to remove the imported Library project first, close and reopen the solution. So that the git system from outside project won't affect current solution's source control and then you can see the expected `Add Solution to Source Control` button.

    2.Click the button and your solution will be put under source control. After that you can import the Library project back, and the change(Importing outside Library project should have changes in solutionName.sln file) will be recorded by solution's git system.

    Note: Though the Library Project and other projects in current solution are all under Source control now, they actually have different git system(.git folder). If your solution depends on the outside Library project heavily, consider making a pure copy(copy of the source files, exclude the git-related files) of that Library project and place it into Solution folder just like other projects. It would be better if all your source files of one program/application are in same version control system. 

    Hope all above helps to resolve your issue and feel free to let me know if my workaround helps.

    Best Regards,

    Dylan


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com

    • Marked as answer by Hong (MA, USA) Thursday, August 6, 2020 11:44 AM
    Thursday, August 6, 2020 5:14 AM

All replies

  • Hi Hong(MA, USA),

    Version control is a system that records changes to a file or set of files under specific path. After we add files of Library project into source control, the Library project would have one newly created `.git` folder which represents its git system. Now if we import the Library Project which has git system into current solution which is not under source control, VS will recognize the git system of Library project as current solution's git system. (Though actually the git system is only for Library project outside current solution folder)

    To add the solution into source control:

    1.We need to remove the imported Library project first, close and reopen the solution. So that the git system from outside project won't affect current solution's source control and then you can see the expected `Add Solution to Source Control` button.

    2.Click the button and your solution will be put under source control. After that you can import the Library project back, and the change(Importing outside Library project should have changes in solutionName.sln file) will be recorded by solution's git system.

    Note: Though the Library Project and other projects in current solution are all under Source control now, they actually have different git system(.git folder). If your solution depends on the outside Library project heavily, consider making a pure copy(copy of the source files, exclude the git-related files) of that Library project and place it into Solution folder just like other projects. It would be better if all your source files of one program/application are in same version control system. 

    Hope all above helps to resolve your issue and feel free to let me know if my workaround helps.

    Best Regards,

    Dylan


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com

    • Marked as answer by Hong (MA, USA) Thursday, August 6, 2020 11:44 AM
    Thursday, August 6, 2020 5:14 AM
  • Thank you very much for the superb answer, Dylan.  It is greatly appreciated. 

    I could add the solution to source control without restarting VS after removing the library under local Git source control.

    Another interesting thing: the solution also includes a library project that is a project of a solution under Git source control linked to Github.  It prevented the solution from being added to source control despite "Add solution to source control..." showed up.  I just unloaded this library (not removal) to make adding the solution to source control succeed. 


    Hong

    Thursday, August 6, 2020 11:32 AM