Click here to Skip to main content
15,569,644 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I've following structure for a .NET Framework project:

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.
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 whereas the ClassLibProj1.dll and ClassLibProj2.dll has version 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. Any help will be appreciated.

What I have tried:

Added <version>$version$</version> to the nuspec file and using following command
nuget pack ConsumerLibProj3.csproj -includereferencedprojects -verbosity detailed
Updated 2-Mar-21 6:51am

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.
Share this answer
RickZeeland 2-Mar-21 12:01pm    
Congrats, 5 points!
The problem is probably that you did not use 'Add as link' for GlobalAssemblyInfo.cs in your projects.
See information here: c# - How do I automatically set all projects in my solution to the same version? - Stack Overflow[^]

You also need to uncomment or remove the lines with e.g.
[assembly: AssemblyVersion("")]
[assembly: AssemblyFileVersion("")]

in the projects AssemblyInfo.cs files.
Share this answer
EpsilonCoder 1-Mar-21 16:00pm    
GlobalAssemblyInfo.cs is added as a link and in all projects, assemblyinfo.cs files have the above two lines commented/removed. In spite of this the versions are different.
RickZeeland 2-Mar-21 2:08am    
Hmmmm, so the problem seems NuGet related.
EpsilonCoder 2-Mar-21 9:36am    
Yes. 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.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900