Given a solution with many projects and different applications (WPF + console) that share libraries, how does a NuGet restore on the solution work?
If I understand it correctly, when I build one of the application projects within the solution (for example the WPF project) via right-click on the project and rebuild, that project acts as the "composition root" (don't know if the terminology is right here) for dependency resolving. So it could happen, that the WPF application would restore a different version of a NuGet package for a class lib during compilation, than the console application would.
If this assumption is correct, what would be the "compostition root" when I build the solution? The defined startup project? Or does a nuget restore always consider every project in a given solution?
How NuGet resolves dependencies is explained in "How NuGet resolves package dependencies" but, short answer, dependency resolution is performed per project.
The current project and its dependencies on other projects and packages are considered but not the entire solution. Yes, if you have a solution with a console app and a WPF app, it is possible for the console app and the WPF app to resolve to different versions of the same package.
When a solution is built, each enabled project in the solution is built. In terms of dependency resolution, there is no difference between building a project directly and building a project by building a solution that lists the project.