Home > Software engineering >  Visual Studio 2022: Add existing project to solution's source control
Visual Studio 2022: Add existing project to solution's source control

Time:10-11

There seem to be hundreds of questions here about how to set up source control in VS, but I could not find one addressing my problem, so please kindly read through my question before flagging as duplicate.

Originally, I had a solution including two projects. That solution as a whole is in source control (git/Azure devops). Also, I have a separate project, that is in source control as well but in a different repository.

Now I wanted to merge that single project into the existing solution, so I just copied the project folder into the solution folder, right-clicked the solution => add existing project. So now the project is in the solution - however, in the source control tab (Git Changes) I don't see any changes, and even when I make changes to whatever project in the solution, the added project does not show up in source control.

I read about VS2022 supporting multiple repositories, which is a nice thing but not what I need here, so I disabled that functionality hoping that VS would then see it as a single repo, but that did not help.

Also tried it manually in git, but failed. This is what I got before and after copying the directory into the solution root, note that I removed all .git* files from the added directory as I don't need any earlier commits, just tried adding a plain folder with files:

# git status
On branch feature/mergeNewProject
Your branch is up to date with 'origin/feature/mergeNewProject'.

nothing to commit, working tree clean

In the added folder I ran

# git init
Initialized empty Git repository in C:/.../MainSolution/AddedProject/.git/

Then I get this when running git status:

#git status
On branch feature/mergeNewProject
Your branch is up to date with 'origin/feature/mergeNewProject'.

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
  (commit or discard the untracked or modified content in submodules)
        modified:   AddedProject (untracked content)

Also followed this question and this as well, without any success.

So just to make this clear, all projects work, all projects are in the same solution in VS2022, but one of them just does not go into source control. I have done that a few times before without any issues but this time something seems to be different...

Any suggestions?

CodePudding user response:

In the added folder I ran git init

No, that does not seem a good idea, since it adds again the .git folder you removed.
It creates a nested Git repository, that would be ignored by your existing project/repository.

Remove the .git created, and to be sure, try git rm --cached AddedFolder (no trailing slash) to remove any special entry in the index of your main repository of the second nested one.

Then check if you can do a git add AddedFolder git commit.

  • Related