如何将 GitLab 与解决方案中的多个项目文件夹一起使用?

How can I use GitLab with multiple project folders inside a solution?

我是版本控制的新手,并且在 gitlab.com 上实现了一个 GitLab 组和其中的一个项目。

我在 Visual Studio 中开发了几个应用程序 - 这些解决方案使用驻留在我计算机上单独文件夹中的项目。

例如:

我为其中一个 DLL 实现了版本控制,但是当我尝试做同样的事情时,例如对于来自 MSVS 内部的应用程序 X,我收到一条错误消息,因为构成解决方案的不同项目(在本例中为 A 和 X)位于不同的文件夹中。

这是一个限制吗,或者有没有办法为一个解决方案提供两个回购协议,一个处理 DLL A 的版本控制,另一个处理 X 的其余可执行代码。

当我打开 X 解决方案时,我看到团队 window 中的所有 A 版本控制,但没有尝试为构建应用程序的代码添加 git 存储库,即 X在上面的描述中。

Visual Studio Git 或“团队”功能仅处理单个存储库。

有一个feature request in state “On Roadmap” for this feature,所以他们打算实现它。

您仍然可以使用 Visual Studio 在各个存储库之间切换然后处理它们,或者您可以使用第三方工具来处理 Git 版本控制。例如 TortoiseGit,您可以通过右键单击上下文菜单在 Windows 资源管理器中使用它。

忽略 Visual Studio 的限制,您有很多选择来处理依赖项及其版本控制。

如果它们是不同的组件,您可以让它们生成 NuGet 包,并将它们添加为依赖项。

如果您想在一个工作区中编辑它们并立即检出存储库(无需间接使用单独的 VS 实例并且必须单独构建 NuGet 包),那么您可能想要使用 git子模块 - 创建一个参考并在子文件夹中检出另一个。

子模块使管理代码变得更加困难和简单,因为您将在存储库中有一个存储库。掌握一些关于它们的技术知识在使用它们时肯定会有所帮助。

对于多个项目,看看 GitLab 13.8(2021 年 1 月)是否可以提供帮助。

Install NuGet packages from your group or subgroup

You can use your project’s Package Registry to publish and install NuGet packages. You simply add your project as a source using the NuGet CLI, Visual Studio, or the .NET CLI.

For example, using the NuGet CLI you can run:

nuget source Add -Name <source_name> \
                -Source "https://gitlab.example.com/api/v4/projects/<your_project_id>/packages/nuget/index.json" \
                 -UserName <gitlab_username or deploy_token_username> \
                 -Password <gitlab_personal_access_token or deploy_token>

This works great if you have a small number of projects.

But if you have multiple projects nested within a group, you might quickly find yourself adding dozens or even hundreds of different sources.
For large organizations with many teams, it’s common for a team to publish packages to their project’s Package Registry alongside the source code and pipelines.
But, they also need to be able to easily install dependencies from other projects within their organization.

Moving forward, you can install packages from your group so you don’t have to remember which package lives in which project.

Simply add your group as a source for NuGet packages and you can install any of the group’s packages.

nuget source Add -Name <source_name> \
                 -Source "https://gitlab.example.com/api/v4/projects/<your_group_id>/packages/nuget/index.json" \
                 -UserName <gitlab_username or deploy_token_username> \
                 -Password <gitlab_personal_access_token or deploy_token>

We hope this feature makes sharing dependencies between projects a little bit easier.

See Documentation and Issue.