Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to automatically update nuget package dependency?

I have have two packages \ projects "A" and "B". Where "B" is depending on "A" and use it as a reference. When my build process in TFS is building "A" it's creating a nuget package from the nuspec and giving it a new version and put's it on my TFS private packages.

My problem is creating a well defined "B" package in every "B" build. In the "B.nuspec" file I write the version of the current "A" package:

<dependencies>
    <group targetFramework=".NETFramework4.5">
        <dependency id="A" version="[1.0.0.3]" />
    </group>
</dependencies>

When ever I'm creating a new "A" package I'm updating the "B" project to use the new "A" release -> this also update the "packages.config" with the latest "A" version as expected. The problem is that the build process of "B" create the "B" package from the nuspec file with the old dependency of "A". And I want it to use the "A" version from the "packages.config".

Is there an automatic way to do it ? (without manually changing the nuspec file every new version of "A") I thought of creating a small "Post-Build" process that read the version from the B-> "packages.config" and write it in "B.nuspec" file in the "A" dependency section. Does TFS support it in an easier way?

like image 211
Aviram Fireberger Avatar asked Apr 12 '17 07:04

Aviram Fireberger


2 Answers

I added a new post build event that trigger a script that's taking the version from the "packages.config" file and write them back to the nuspec file.

I upload the script and the post build event to my GIT for anyone who will need it.

https://github.com/avrum/NuspecAutoUpdate

like image 63
Aviram Fireberger Avatar answered Oct 09 '22 13:10

Aviram Fireberger


This question is similar to auto-update your NuGet packages at build time Cannot automatically update a NuGet package to the latest version during build

You need to add a new build step (such as powershell script) to your build process/ build definition to achieve it.

like image 41
PatrickLu-MSFT Avatar answered Oct 09 '22 11:10

PatrickLu-MSFT