在Azure DevOps中的其他存储库中更新NuGet参考 [英] Updating NuGet reference in a different repo in Azure DevOps

查看:78
本文介绍了在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.存储库B引用存储库A生成的DLL(通过NuGet程序包).

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

回购A的CD管道将NuGet程序包(在回购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]的packages文件夹中没有新的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.

预构建事件在这里有帮助,但是我希望从Azure Repos中获取Repo B完全是最新的.

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

下面是回购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.

简单的方法是:

使用以下命令行将预构建事件添加到存储库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中构建项目时更新引用.但是这种方式的局限性在于该方法只会修改我们的本地文件,而不会直接修改存储库中的文件.我们仍然需要手动将更改提交到存储库.

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.

复杂的方法是:

在存储库A的CD管道中添加命令行任务,以使用git命令行克隆存储库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.

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

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 <repo> <directory>克隆存储库时,需要在源链接中提供证书,通常使用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

对于您的情况,应为:

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

那我可以成功克隆它.

希望这会有所帮助.

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

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