Coder Social home page Coder Social logo

Comments (4)

zivkan avatar zivkan commented on June 18, 2024

@frederick-brier In the schema section of the docs, it says for allowedVersions:

It does not affect what package is installed during an install or restore operation.

Bringing the a concept similar to floating versions to packages.config is not possible because when you install a package with packages.config, it modifies the project file to contain something like this: <HintPath>../../packages/MyProj.PkgId.1.0.0/lib/net472/MyProj.PkgId.dll</HintPath>.

If NuGet restored version 1.0.5, then that path will be wrong, and the project's not going to build. You need to use the Package Manager UI or Package Manager Console to install upgrade the package.

This is one of the things that is improved/fixed with PackageReference, but there are limitations in which project types can migrate from packages.config to PackageReference

from docs.microsoft.com-nuget.

frederick-brier avatar frederick-brier commented on June 18, 2024

from docs.microsoft.com-nuget.

zivkan avatar zivkan commented on June 18, 2024

When I started, I really didn't think this response would end up as long as it did. Sorry. However, as the saying goes, I don't have time to write a short letter, so I wrote a long one instead.

Could you please explain how I might be misinterpreting this documentation?

The first documentation page you linked, https://learn.microsoft.com/en-us/nuget/consume-packages/reinstalling-and-updating-packages#constraining-upgrade-versions, discusses installing and upgrading packages with Visual Studio's Package Manager UI and Package Manager Console. If you take the "Constraining upgrade versions" section out of the context of the rest of the document, I can see how coming in with the idea that restore should install some version with the rage, then the documentation doesn't dispel that idea.

However, I believe that similar to how the documentation doesn't explicitly say "this doesn't affect restore", it also doesn't say that it is used by restore. The first sentence of the section says "By default, reinstalling or updating a package ...". However, when nuget looks at the packages listed in packages.config and downloads them, this action is called restore. Restore is a different action than re-install or update. Again, understandable misunderstanding, and I wish that the NuGet team used clearer language, and had much clearer documentation, but I joined the team after the product was over 7 years old, so I couldn't prevent historic mistakes.

The second link you provided was the packages.config reference documentation, where I pulled the quote from my previous reply "A range of allowed versions for this package applied during package update (see Constraining upgrade versions. It does not affect what package is installed during an install or restore operation.". So, it explicitly states that this metadata is only used for update, and that it does not affect install or restore. Again, it unfortunately requires the reader to understand the difference between update and restore (and install).

Second, when using CMake with the Ninja generator, there is no project file with elements or elements.

In this case, while it's interesting that you, and the part of the community who are working in the way you describe, have found a way to make NuGet work for you, it's outside of how NuGet was designed to work. All the documentation we have on using and installing packages is for MSBuild projects, primarily .NET projects.

If you create a MSBuild based C++ project, and you use either the Package Manager UI or Package Manager Console to install a package, NuGet will create the packages.config file, but it will also modify the vcxproj file to directly reference any package assets. Unless you created a C++/CLI project, there's an exception to every rule, but in this case it uses PackageReference which fixes many issues learned during the first 5 years of nuget's packages.config existance.

Anyway, for C++ MSBuild projects with packages.config, the vcxproj changes is usually only msbuild props/targets files which will result in the vcxproj having something like <Import Project="..\packages\packageid.1.2.3\build\packageid.props" Condition="Exists(...)" />. Here we can again see the package version in the path, which needs to match the version that nuget restore during CI pipelines.

If the CMake or Ninja generator community would like improved tooling, we don't have much documentation on the NuGet Client SDK, but we do have samples for getting package metadata (which includes the list of all versions the package source has, to the highest in a range can be selected), [how to download a package](https://learn.microsoft.com/en-us/nuget/reference/nuget-client-sdk#download-a-package]. Unfortunately we don't have a sample for how to exact a nupkg, but if anyone using the NuGet Client SDK has questions, I can tell them in the NuGet.Packaging package, there's a class named PackageExtractor.

Unfortunately is CMake/Ninja generator want to start using NuGet as an API, then while it provides more flexibility, it also has more responsibility since someone will need to maintain the app/integration, so very understandable if nobody wants to take that responsibility. But in that case, people using the tooling are limited to existing features.

However, I'd like to reiterate that how CMake and Ninja generator is using NuGet is outside the design for how NuGet was intended to be used. NuGet has always been a tool that worked with MSBuild projects.

IMHO, this is a bug.

At the bottom of each documentation page are two links, one to report an issue with the documentation page, which you used to create this issue. The other is for product issues, which would have taken you to https://github.com/NuGet/Home. If you wish to report a product bug, or feature suggestion, then please do so in the Home repo. This issue, reporting a documentation bug, I can see how there's room for improvement, and hopefully someone will update the docs to make it clearer, so other people don't have the same confusion you did. But I wanted to help by explaining that this is not how NuGet works, rather than ignore this issue until the documentation is improved.

While your suggestion, nuget restore, finding some suitable version within the allowedRange makes sense in the context for how you wish to use it, NuGet's primary use-case, with MSBuild projects (mostly .NET, and to a very small extent vcxproj C++ projects) it would unfortunately be harmful. If nuget restored a package other than the exact version specified, then build would fail for these MSBuild projects, since they contain imports and hint paths pointing to the package directory, rather than an error saying the package version couldn't be found. The error that the package version couldn't be found will make it easier and quicker for developers to investigate, rather than more obscure build errors, probably about APIs that can't be found, or in the case of packages like SourceLink, the error would be completely silent, and the developer would need to notice that their pdbs are missing source link metadata. Therefore, I'm not optimistic that NuGet's new issue triage team would accept a feature or design change request to allow what you're asking for. It would benefit a much smaller number of customers than the number of customers who would cause more difficult to investigate failures.

Anyway, I have a lot of other work I need to do, so I'm not going to spend time editing this comment to be shorter. I just wanted to help by helping understand how nuget works, rather than ignore the issue until documentation is changed to explain that that's not how nuget works.

from docs.microsoft.com-nuget.

frederick-brier avatar frederick-brier commented on June 18, 2024

from docs.microsoft.com-nuget.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.