Search code examples
tfsnugetnuget-packagenuget-servernuspec

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?


Solution

  • 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