I have set up a multi-repo in Azure DevOps using Git. Assume I have 2 repos (Repo A and B) for simplicity.
Repo A\'s outcome is a common library DLL. Repo B referenc
This can be done a bit differently than asked.
Using Project References (Newer projects):
Change your Repo B project's package reference version to get the latest using the wilcard symbol *
in the Version
attribute.
<PackageReference Include="MyPackageName" Version="*" />
Using packages.config
packages.config
does not support the wildcard symbol and takes a few more steps.
You will need to add the following to your nuget.config
file inside the <configuration>
section:
<config>
<add key="dependencyversion" value="Highest" />
</config>
Be sure that the nuget.config is a part of the repo.
Then In the pipeline's Nuget restore
task under the Feeds to use
section select Feed in my NuGet.config
and then specify the path to the repo's nuget.config.
In either case, when Repo B compiles in the pipeline it will grab the latest. When the repo is pulled down clean or for the first time it will grab the latest on the initial compile as well and on any new version that has been published.
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.
The simple way is:
Add a Pre-build event to the project in the Repo B with following command line:
nuget.exe update $(ProjectDir)packages.config
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.
The Complex way is:
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>
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
Update:
When you use git clone <repo> <directory>
to clone the repo, you need to provide your certificate in your source link, usually using PAT:
The link looks like:
https://<OrganizationName>@dev.azure.com/<OrganizationName>/MyTestProject/_git/TestSample
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.
Hope this helps.