Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

nuget packaging with version parameter and dependencies

Tags:

nuget

I've got an issue when packaging new packages with nuget in that when i specify the version by the command line it applies it to the package but not to dependencies. I.E.

NuGet.exe pack myproject.csproj -Version 3.0.4.3373

with a nuspec file

<?xml version="1.0"?>
<package>
<metadata>
    <id>MyProject</id>
    <version>$version$</version>
    <authors>Me</authors>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <description>A description.</description>
    <copyright>Copyright 2014</copyright>
    <dependencies>
        <dependency id="My.First.Dependency" version="[$version$]" />
        <dependency id="My.Second.Dependency" version="[$version$]" />
    </dependencies>
</metadata>
</package>

results in a package with the version 3.0.4.3373 but the dependencies are all written in as 1.0.0.0, which is not what I wanted. I want them to be the same version.

What have I got wrong here. I'm sure I've had this working before. I think I've used both 2.5 and 2.8 of nuget.exe for this.

like image 537
cdmdotnet Avatar asked Mar 24 '26 18:03

cdmdotnet


1 Answers

Seems like a very old bug while using a csproj combined with nuspec (which is still there with NuGet 3.5) ...

One way of making this working is by adding an extra property

<?xml version="1.0"?>
<package>
<metadata>
    <id>MyProject</id>
    <version>$version$</version>
    <authors>Me</authors>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <description>A description.</description>
    <copyright>Copyright 2014</copyright>
    <dependencies>
        <dependency id="My.First.Dependency" version="[$PackageVersion$]" />
        <dependency id="My.Second.Dependency" version="[$PackageVersion$]" />
    </dependencies>
</metadata>
</package>

And then update your command

NuGet.exe pack myproject.csproj -Version 3.0.4.3373 -Properties "PackageVersion=3.0.4.3373"

It is not that clean, but it works.

like image 79
Seb T. Avatar answered Mar 26 '26 10:03

Seb T.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!