Updating NuGet reference in a different repo in Azure DevOps

后端 未结 2 1421
Happy的楠姐
Happy的楠姐 2021-01-07 09:33

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

2条回答
  •  既然无缘
    2021-01-07 09:48

    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  
    

    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 to clone the repo, you need to provide your certificate in your source link, usually using PAT:

    The link looks like:

    https://@dev.azure.com//MyTestProject/_git/TestSample
    

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

    https://@dev.azure.com//MyTestProject/_git/TestSample
    

    For your case, it should be:

    https://@xxxxx.Visualstudio.com/....
    

    Then I could clone it successfully.

    Hope this helps.

提交回复
热议问题