'How to pass a Version-Range for a Project reference into the nuspec file?

I have a ProjectA that has a ProjectReference LibraryB. Now I want to achieve the Following:

  • If I Pack ProjectA I want to have the Library B as Dependency with a specific Version Range.

Currently, for packing, I use the Visual-Studio Command "Pack" in Visual-Studio 2019.

My Problem: If I write the Version range into the .csproj file and pack ProjectA, the current Version of LibraryB is written into the nuspec file and not the Version-range I defined in the .csproj-file.

So in my .csproj-file I have the following:

<ProjectReference Include="..\LibraryB\LibraryB.csproj" Version="[2.1.1, 2.1.6)"/>

In the .nuspec-file of the project I want the following text:

  <group targetFramework="net5.0-windows7.0">
    <dependency id="LibraryB" version="[2.1.1, 2.1.6)" exclude="Build,Analyzers" />
  </group>

The Text that I get is:

  <group targetFramework="net5.0-windows7.0">
    <dependency id="LibraryB" version="2.1.5" exclude="Build,Analyzers" />
  </group>

So is there any possibility to get this Version Range into the .nuspec-file out of the csproj-file? For a NuGet-Dependency, it's working fine.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source