Push an existing project into a new Azure DevOps repository in Visual Studio 2022
Asked Answered
E

4

7

I have an existing Visual Studio project with existing code
and a newly created Azure DevOps (git) project with an empty repository.

Now from Visual Studio 2022 I want to push my project into the DevOps repository.

This should be a very common problem, I guess.

However, when I use "Create Git Repository", it won't let me create the repository with the same name, since it already exists, because DevOps automatically creates a repository with the same name for a new project:

enter image description here

So I don't really need to create a new repository, but just connect to the existing one, so I can push the project there. But I haven't found a good way to do so.

My workaround so far was:
- Create the new DevOps project "MyApp"
- Create a second repository "Dummy" there, because there must be at least one
- Delete the "MyApp" repository
- Create a new "MyApp" repository from Visual Studio
- Delete the "Dummy" repository

That works, but it's obviously stupid. There should be a straightforward, obvious way to do it.

I'm really confused I couldn't find a good answer online, as I believe this must be the second most common use case (after creating both a new DevOps project and a new VS project at the same time). Maybe I'm just terribly bad at googling.

Erode answered 3/8, 2022 at 13:57 Comment(0)
E
3

In the image, under Other you have Existing Remote. You can use this and add the url to the repo that was created by default

Endoscope answered 3/8, 2022 at 14:48 Comment(1)
Doesn't work in VS2022, you add the url to the existing remote repo and the push button remains disabled.Ricebird
L
4

Please follow below steps to add an existing project into a new Azure DevOps Git repo in VS 2022:

  1. View -> Team Explorer enter image description here

  2. Manage Connections -> Connect to a project enter image description here

  3. Add an Azure DevOps server or online service account -> Select the project and your new repo -> Clone enter image description here

  4. After that, go to Solution Explorer -> Select the root folder and right-click -> Select "Open Folder in File Explorer".

  • enter image description here
  1. Open your local existing project folder, copy the solution directory to the folder opened in step 4, then go to the Git changes explorer, check the changes and Commit all. If you cannot see the Git explorer, then please open it from View -> Git Changes. enter image description here

  2. Push the changes to the remote repo, then check the repo in Azure DevOps. enter image description here enter image description here

Lychnis answered 4/8, 2022 at 10:1 Comment(0)
E
3

In the image, under Other you have Existing Remote. You can use this and add the url to the repo that was created by default

Endoscope answered 3/8, 2022 at 14:48 Comment(1)
Doesn't work in VS2022, you add the url to the existing remote repo and the push button remains disabled.Ricebird
S
1

You properly already have this worked out but this is an issue with VS 2022. This worked in 2017 and 2019. You could create a new project with an initial repository with those editions but not with 2022.

The solution is to manually create your project on DevOps then rename default repository and then add your 'new' repository to that project from Visual Studio 2022.

I have reported this as a bug to the Visual Studio team over ½ a year ago but they have done nothing about it so far.

Sometimes I install a 2019 or 2017 and add new projects with those versions and then move back to 2022.

Sanfred answered 25/9, 2022 at 9:46 Comment(2)
Thank you for making that clear. Your solution also is my "workaround" solution I described, which is insane. I can't believe they haven't fixed this so far. The answer I accepted works fine as well, but still requires copying the remote URL from DevOps, which shouldn't be necessary.Erode
Having read you initial post again I now like to update my answer. What I mean is that it was most likely never possible to upload a repository to an existing project in VS2017 or VS2019 but in those editions you could at least create a new project and the files in the solution would become the initial repository. The 'create new project' seems to not be available anymore. And if you create it beforehand you end up with conflicting repository names if you name it all the same I currently fix it by manually creating a project and renaming the default repository, upload then delete renamed.Sanfred
S
1

The easiest and "safest" way I have found to do this.

  1. Rename your local solution directory to something else (Project to ProjectV2)
  2. Clone the repository from AzDO (Creating new Project directory)
  3. Copy the files from ProjectV2 back into Project.
  4. Check it in.

The main advantage is that you have a backup of your code should something go wrong. Probably slightly more steps than you wanted but gives you lots of control.

Skitter answered 12/4 at 18:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.