Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nuget pack does not recognize $version$ in dependencies

Tags:

c#

nuget

So, previously we called nuget pack with the nuspec file (nuget pack myproj.nuspec). The nuspec looked something like this:

<package>
  <metadata>
    <version>$version$</version>
    [more properties]
    <dependencies>
      <dependency id="MySubProj" version="$version$" />
      [more explicit dependencies]
    </dependencies>
  </metadata>  
</package>

I switched the call to (nuget pack myproj.csproj) so our always-outdated explicit dependencies would be auto-generated.

Everything works great, except now the finished nuspec is something like

<package>
  <metadata>
    <version>1.2.3.4</version>
    [more properties]
    <dependencies>
      <dependency id="MySubProj" version="0.0.0.0" />
      [more explicit dependencies]
    </dependencies>
  </metadata>  
</package>

While the correct version of MySubProj would also be 1.2.3.4.

More infos:

  • MySubProj is a project in the same solution
  • It is bundled into a separate nuget package
  • The version of the MySubProj nuget package as well as the version of the bundled dll are correct.

I don't get what I am doing wrong really and why it would work when using the nuspec directly vs the csproj :/

like image 572
FrankyBoy Avatar asked Jul 01 '26 14:07

FrankyBoy


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

<package>
  <metadata>
    <version>$version$</version>
    [more properties]
    <dependencies>
      <dependency id="MySubProj" version="$PackageVersion$" />
      [more explicit dependencies]
    </dependencies>
  </metadata>  
</package>

And then update your command

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

It is not that clean, but it works.

like image 180
Seb T. Avatar answered Jul 03 '26 03:07

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!