How to keep same version for all the projects while generating NuGet package using pack command?

Epsi Coder 1 Reputation point
2021-03-02T16:12:21.297+00:00

I've following structure for a .NET Framework project:

Copy Code-->ProjectSoln

-------->ClassLibProj1

-------->ClassLibProj2

-------->ConsumerLibProj3

I've defined GlobalAssemblyInfo.cs file at solution level and added the reference to this file in all the 3 projects. ConsumerLibraryProj3 has project reference to ClassLibraryProj1 and ClassLibraryProj2. GlobalAssemblyInfo.cs is added as a link and in all projects. I've added nuspec file in the ConsumerLibProj3 that contains <version>$version$</version>. I'm generating Nuget Package for the ConsumerLibraryProj3 using following command

nuget pack ConsumerLibProj3.csproj -includereferencedprojects -verbosity detailed

The package gets generated successfully, but the version of the ClassLibProj1 and ClassLibProj2 dlls in the package is not the latest. e.g. in the package ConsumerLibProj3.dll has version 1.0.0.2 whereas the ClassLibProj1.dll and ClassLibProj2.dll has version 1.0.0.1. The expectation is that all the three dll's should have same version because the the version is coming from the GlobalAssemblyInfo.cs file. The solution is using .NET Framework type project.

Weird thing is that when I build the solution the output folder contains dll's with correct latest version. Not sure why and from where nuget is picking up the older versions of dll's. I cleared the cache as well. I also tried to build the solution with different publishing modes(debug/release). But nothing is working so far.

Any help will be appreciated.

Thanks

.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,367 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Tianyu Sun-MSFT 27,266 Reputation points Microsoft Vendor
    2021-03-03T04:35:51.077+00:00

    Hi @Epsi Coder ,

    Thank you for taking time to post this issue in Microsoft Q&A forum.

    From the latest command line you used, I see you added -build and -properties configuration=release. Actually for the “Configuration” property, the default is “Debug”, if you don’t add this option, during the packing process, the nuget.exe will go to check and look for the dll files in the “Debug” folder, even if you had selected Release mode in VS or set the Release configurations in some settings files.(This is the document which describes the options - properties)

    Perhaps, the previous version of dll files are included in your “Debug” folder, and after rebuilding the latest version of dll files had generated into the “Release”(or “Debug”) folder. And, the most important thing, I think, is this command: -properties configuration=release is needed for “Release” build.

    Best Regards,
    Tianyu

    • If the answer is helpful, please click "Accept Answer" and upvote it.
      Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
    1 person found this answer helpful.

  2. Epsi Coder 1 Reputation point
    2021-03-02T16:52:13.71+00:00

    At last I was able to resolve this issue by forcing the nuget to use release configuration while packing. Surprisingly, I was building the solution with Release profile but still nuget was getting confused somehow. I used following command

    nuget pack ConsumerLibProj3.csproj -includereferencedprojects -build -properties configuration=release -verbosity detailed

    Thanks for the help.

    0 comments No comments