The Problem
I’m developing an integrating solution in Visual Studio 2019 that needs to incorporate several previously developed proof-of-concept prototypes on Azure DevOps. Some of these existing prototypes are:
- Single-project repositories (just one
.csproj) - Multi-project solutions (multiple
.csprojfiles in one.sln)
For single-project repositories, Git submodules work perfectly. However, I’m struggling with the multi-project solutions where I only need one specific project/folder/module from the repository.
Current approaches I’ve tried:
-
Using Git submodules for the entire repository:
MyNewSolution/ ├── src/ │ └── externals/ │ └── ExistingRepo/ # Git submodule containing ALL projects │ ├── Project1/ │ ├── Project2/ # The only one I need │ └── Project3/ -
Manual copy of specific project folder:
MyNewSolution/ ├── src/ │ └── externals/ │ └── Project2/ # Manually copied, losing version control connection
The Question
What is the canonical way to include a specific module/folder from a multi-project repository as a git submodule? I want to:
- Maintain version control connection to the original project
- Avoid cluttering my new solution with unnecessary projects
- Follow best practices for both Git and Visual Studio
Minimal Working Example
Original Repository Structure (ExistingRepo):
ExistingRepo/
├── ExistingRepo.sln
├── Project1/
│ └── Project1.csproj
├── Project2/
│ └── Project2.csproj
└── Project3/
└── Project3.csproj
New Solution Structure (desired):
MyNewSolution/
├── MyNewSolution.sln
└── src/
├── MainProject/
│ └── MainProject.csproj
└── externals/
└── Project2/ # Want this as a submodule from ExistingRepo
└── Project2.csproj
What are the best practices for achieving this structure while maintaining proper version control?
What I’ve Considered
-
Git sparse checkout (tried unsuccessfully)
- Pros: Keeps git connection
- Cons: Seems complex for CI/CD
-
Breaking up original repository (the one I am moving forward right now)
- Pros: Clean separation
- Cons: Major refactoring of existing codebase
-
Accepting full repository as submodule (don’t like this)
- Pros: Simple git management
- Cons: Cluttered solution
-
NuGet package (don’t know how to do Releases/Artifacts/Piplines on Azure DevOps)
- Pros: Clean dependency management
- Cons: Overhead of package management