在 Azure DevOps 的不同存储库中更新 NuGet 引用 [英] Updating NuGet reference in a different repo in Azure DevOps

查看:15
本文介绍了在 Azure DevOps 的不同存储库中更新 NuGet 引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用 Git 在 Azure DevOps 中设置了一个多存储库.为简单起见,假设我有 2 个存储库(存储库 A 和 B).

I have set up a multi-repo in Azure DevOps using Git. Assume I have 2 repos (Repo A and B) for simplicity.

回购 A 的结果是一个公共库 DLL.Repo B 引用了 Repo A 生成的 DLL(通过 NuGet 包).

Repo A's outcome is a common library DLL. Repo B references Repo A's generated DLL (via a NuGet package).

Repo A 的 CD 管道将 NuGet 包(在 Repo A 的 CI 管道期间打包)推送到我的 Azure Artifacts 源.

The CD pipeline of Repo A pushes the NuGet package (which was packed during the CI pipeline of Repo A) to my Azure Artifacts feed.

有没有办法在Repo A的CD管道中添加一个任务来自动改变Repo B的项目中的NuGet包引用(到更新的版本)?这样,当 Repo B 被拉到本地存储库时,引用将被更新,而不是通过 NuGet 包管理器并在 Visual Studio 中手动更新?

Is there a way to add a task in the CD pipeline of Repo A to automatically change the NuGet package reference (to a newer version) in the project of Repo B? This way, when Repo B gets pulled on the local repository, the reference would be updated instead of going through the NuGet Package Manager and updating manually in Visual Studio?

更新:

应用您的建议后,一切正常,除了当我将 RepoB 的更改拉到本地存储库时,[Repo B] 的包文件夹中没有 Repo A 的新 NuGet 包,我有从包管理器手动获取它.

After applying your suggestions, everything is working perfectly except the fact that when I pull the changes of RepoB to my local repo, the new NuGet package of Repo A is not available in the packages folder [of Repo B] and I have to manually get it from the Package Manager.

预构建事件在这里有所帮助,但我希望 Repo B 在从 Azure Repos 中提取时完全保持最新状态.

Pre-Build event helps here but I want Repo B be fully up-to-date upon pulling from Azure Repos.

以下是 Repo A 的 CD 管道.

Below is the CD pipeline of Repo A.

推荐答案

有没有办法在Repo A的CD管道中添加一个任务来自动改变Repo B的项目中的NuGet包引用(到更新的版本)?

Is there a way to add a task in the CD pipeline of Repo A to automatically change the NuGet package reference (to a newer version) in the project of Repo B?

没有这种开箱即用的方法来做到这一点.

There is no such out-of-the-box approach to doing this.

简单的方法是:

使用以下命令行向 Repo B 中的项目添加预构建事件:

Add a Pre-build event to the project in the Repo B with following command line:

nuget.exe update $(ProjectDir)packages.config

如果 Repo B 被拉到本地仓库时,在 repo B 中构建项目时会更新引用.但这种方式的限制是这种方法只会修改我们的本地文件,不会直接修改repo中的文件.我们仍然需要手动提交对 repo 的更改.

In case, when Repo B gets pulled on the local repository, the reference would be updated when you build the project in the repo B. But the limitation for this way is that this method will only modify our local files and will not directly modify the files in the repo. We still need to submit the changes to the repo manually.

复杂的方法是:

在Repo A的CD管道中添加命令行任务,使用git命令行克隆repo B:

Add a command line task in the CD pipeline of Repo A to use git command line to clone repo B:

git config --global user.email "xxx@xyz.com"
git config --global user.name "Admin"

git clone <repo> <directory>

然后添加powershell或任何其他任务来更新项目文件中的ReferenceHintPath信息和packages.config 文件.

Then add powershell or any other task to update the Reference, HintPath info in the project file and the package version in the packages.config file.

修改文件后,添加另一个命令行任务将更改提交到repo:

After modifying the files, add another command line task to submit the changes to the repo:

git commit -m "Update package version"

git push -u origin master

更新:

当你使用 git clone 时<directory> 克隆repo,你需要在你的源链接中提供你的证书,通常使用PAT:

When you use git clone <repo> <directory> to clone the repo, you need to provide your certificate in your source link, usually using PAT:

链接看起来像:

https://<OrganizationName>@dev.azure.com/<OrganizationName>/MyTestProject/_git/TestSample

然后我们需要用 PAT 替换第一个 OrganizationName.所以,它将是:

Then we need to replace the first OrganizationName with PAT. So, it will be:

https://<PAT>@dev.azure.com/<OrganizationName>/MyTestProject/_git/TestSample

对于您的情况,应该是:

For your case, it should be:

https://<PAT>@xxxxx.Visualstudio.com/....

然后我就可以成功克隆它了.

Then I could clone it successfully.

希望这会有所帮助.

这篇关于在 Azure DevOps 的不同存储库中更新 NuGet 引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆