I'm trying to figure out where different versions of NuGet packages get stored when I build a project. Especially how different versions of a package are being taken into consideration. Imagine the following setup:
- ClasslibA.csproj
- VersionA.cs
- ClasslibB.csproj
- VersionB.cs
- Consumer.csproj
- Program.cs
Both ClasslibA and ClasslibB are being build into NuGet packages. For ClasslibA there is a version 1.0.0 and 1.1.0 package available.
VersionA has a public const string Current
that contains the version number of the package (either 1.0.0 or 1.1.0). VersionB references ClasslibA v1.0.0 and has a public const string Current = $"I'm relying on VersionA v{VersionA.Current}."
. The Consumer project is a console app referencing ClasslibA v1.1.0 and ClasslibB. The Program.cs just writes two statements:
Console.WriteLine($"Consumer VersionB: {VersionB.Current}");
Console.WriteLine($"Consumer VersionA: {VersionA.Current}");
I created that setup in a company repository (which is why I'm not able to share it, sry), ran the Consumer app, and it printed out
Consumer VersionB: I'm relying on VersionA v1.0.0.
Consumer VersionA: 1.1.0
So apparently both versions are being utilised. But when I look into the build folder, there's only one ClasslibA.dll and one ClasslibB.dll. Copying the build output to a fresh VM with only the .Net runtime installed yielded the same result as running from Visual Studio.
How/where are different versions of the same package stored in the build output?
https://learn.microsoft.com/en-us/nuget/concepts/dependency-resolution states
When multiple packages have the same dependency, then the same package ID can appear in the graph multiple times, potentially with different version constraints. However, only one version of a given package can be used in a project, so NuGet must choose which version is used.
How can only a single version be used if my setup clearly shows that there are multiple different package versions used in the final output?
Also - Does it all work the same in .Net and .Net Framework?
Reading up on the internet, which answered my first initial question but brought up new ones. I also set up the experimental setup described above.