في هذه المقالة

Package consumption workflow

03/22/2018

تستغرق القراءة 2 دقائق

المساهمون

في هذه المقالة

Between nuget.org and private package galleries that your organization might establish, you can find tens of thousands of highly useful packages to use in your apps and services. But regardless of the source, consuming a package follows the same general workflow.

* Visual Studio and dotnet.ex` only. The nuget install command does not modify project files or packages.config; entries must be managed manually.

NuGet remembers the identity and version number of each installed package, recording it in either packages.config or the project file (using PackageReference), depending on project type and your version of NuGet. With NuGet 4.0+, PackageReference is preferred, although this is configurable in Visual Studio through the Package Manager UI options. In any case, you can look in the appropriate file at any time to see the full list of dependencies for your project.

Tip

It's prudent to always check the license for each package you intend to use in your software. On nuget.org, you find a License Info link on the right side of each package's description page. If a package does not specify license terms, contact the package owner directly using the Contact owners link on the package page. Microsoft does not license any intellectual property to you from third party package providers and is not responsible for information provided by third parties.

NuGet also makes sure that the target frameworks supported by the package are compatible with your project. If the package does not contain compatible assemblies, NuGet displays an error. See Resolving incompatible package errors.

When adding project code to a source repository, you typically don't include NuGet packages. Those who later clone the repository or otherwise acquire the project, including build agents on systems like Visual Studio Team Services, must restore the necessary packages prior to running a build:

Package Restore uses the information in the project file or packages.config to reinstall all dependencies. Note that there are differences in the process involved, as described in Dependency Resolution. Also, the diagram above does not show a restore command for the Package Manager Console because you're with the Console you're already in the context of Visual Studio, which typically restores packages automatically and provides the solution-level command as shown.

Occasionally it's necessary to reinstall packages that are already included in a project, which may also reinstall dependencies. This is easy to do using the nuget reinstall command or the NuGet Package Manager Console. For details, see Reinstalling and Updating Packages.

Finally, NuGet's behavior is driven by Nuget.Config files. Multiple files can be used to centralize certain settings at different levels, as explained in Configuring NuGet Behavior.