* Preface < Preface>
* What is?NuGet? < What is?nuget>
* Why useNuGet < Why usenuget>
* NuGet Advantages < Advantages>
* Use < Use>
* Get-Help NuGet
* Install-Package
* Get-Package <>
* Uninstall-Package
* MakeNuGet Library package < Makenuget Library package>
* buildNuGet The server < buildnuget The server>
* uploadNetGet Library package < uploadnetget Library package>
* Newly addedNuGet source < Newly addednuget source>
* summary < summary>

What is?NuGet?

Nuget It is a.NET Open source projects under the platform, It isVisual Studio Extension. in useVisual Studio Based on Development.NET
Framework Application time,Nuget Can add to the project, Removing and updating references is faster and easier.

Why useNuGet

If our project development does not need to refer to any third-party library package or our own public library package, Then useNuGet No effect, But the opposite is true, Logging is required for any project, The best case is that we have a common logging module, Any old or new project we can refer to, No more development. In terms of our own projects,FC,FGOnline,FGMain,FGClient,FGServer, At present, we do not have a public log module, Bottom useKernal And other libraries may not be the same version, Even if it's the same version, we always develop thedll Handmade copy to copy. In terms of new projects, this increases the workload and development, So we need a package management mechanism to manage our private packages and the third-party packages we need to use.

NuGet Advantages

takeAsyncModule.NetMQ.dll Give an example,AsyncModule.NetMQ.dll rely onNetMQ.dll, andNetMQ.dll Also rely on
At present, where we need database connection, we need to referenceAsyncModule.NetMQ.dll, We may bake it by hand into the project we need, But because of
AsyncModule.NetMQ.dll Need dependenceNetMQ.dll, So we also need to handNetMQ.dll Copy to our project, Also due toNetMQ.dll Need dependence
AsyncIO.dll, So we also need to handAsyncIO.dll
Copy to our project. Depending on it, there will be some problems, For example, we forgot to copy, Or the version we copied is not what we need right now, It will lead to many problems.
NuGet So we can avoid this problem. If the library package we need has been imported into our library package server, Then we only need one statement to refer to thedll, meanwhileNuGet
Will automatically reference its dependent packages together into our project, It's completely automatic.


stayVS Find in Package Manager Console Dialog box

If not found on the interface, From tools-NuGet Package Manager Search for

Get-Help NuGet

UseGet-Help NuGet Command view help
PM> Get-Help nuget TOPIC about_NuGet SHORT DESCRIPTION Provides information
about NuGet Package Manager commands. LONG DESCRIPTION This topic describes the
NuGet Package Manager commands. NuGet is an integrated package management tool
for adding libraries and tools to .NET projects. The following NuGet cmdlets
are included. Cmdlet Description ------------------
---------------------------------------------- Get-Package Gets the set of
installed packages. With -ListAvailable, gets the set of packages available
from the package source. Install-Package Installs a package and its
dependencies into the project. Uninstall-Package Uninstalls a package. If other
packages depend on this package, the command will fail unless the –Force option
is specified. Update-Package Updates a package and its dependencies to a newer
version. Add-BindingRedirect Examines all assemblies within the output path for
a project and adds binding redirects to the application (or web) configuration
file where necessary. Get-Project Returns a reference to the DTE (Development
Tools Environment) for the specified project. If none is specifed, returns the
default project selected in the Package Manager Console. Open-PackagePage Open
the browser pointing to ProjectUrl, LicenseUrl or ReportAbuseUrl of the
specified package. Register-TabExpansion Registers a tab expansion for the
parameters of a command. SEE ALSO Online documentation: Get-Package Install-Package
Uninstall-Package Update-Package Add-BindingRedirect Get-Project
Open-PackagePage Register-TabExpansion

UseInstall-Package Install library package, Automatically install the currentFramework Known library packages and dependent packages, Error will be prompted if not supported.
PM> Install-Package AsyncModule.NetMQ Attempting to resolve dependency 'NetMQ
(≥'. Attempting to resolve dependency 'AsyncIO (≥ 0.1.26)'. Installing
'AsyncIO'. Successfully installed 'AsyncIO'. Installing
'NetMQ'. Successfully installed 'NetMQ'. Installing
'AsyncModule.NetMQ 1.1.0'. Successfully installed 'AsyncModule.NetMQ 1.1.0'.
Adding 'AsyncIO' to NuGet.Client. Successfully added 'AsyncIO' to NuGet.Client. Adding 'NetMQ' to NuGet.Client. Successfully
added 'NetMQ' to NuGet.Client. Adding 'AsyncModule.NetMQ 1.1.0' to
NuGet.Client. Successfully added 'AsyncModule.NetMQ 1.1.0' to NuGet.Client.
Pay attention to the corresponding library and package source during installation


UseGet-Package Install library package
PM> Get-Package Id Version Description/Release Notes -- -------
------------------------- AsyncIO AsyncIO AsyncModule.NetMQ 1.1.0
Be based onNetMQ AsynchronousSocket frame NetMQ A 100% native C# port of the lightweight high
performance messaging library ZeroMQ

UseUninstall-Package Uninstall installed library packages, Dependent packages will not be uninstalled automatically, If necessary, you need to manually uninstall the dependency package
PM> Uninstall-Package AsyncModule.NetMQ Removing 'AsyncModule.NetMQ 1.1.0'
from NuGet.Client. Successfully removed 'AsyncModule.NetMQ 1.1.0' from
NuGet.Client. Uninstalling 'AsyncModule.NetMQ 1.1.0'. Successfully uninstalled
'AsyncModule.NetMQ 1.1.0'.
If the library package has multiple versions, add-Version The version number parameter installs the library package of the specified version. If the specified version of the dependent package is already installed, it will not be reinstalled again.
PM> Install-Package AsyncModule.NetMQ -Version 1.1.0 Attempting to resolve
dependency 'NetMQ (≥'. Attempting to resolve dependency 'AsyncIO (≥
0.1.26)'. Installing 'AsyncModule.NetMQ 1.1.0'. Successfully installed
'AsyncModule.NetMQ 1.1.0'. Adding 'AsyncModule.NetMQ 1.1.0' to NuGet.Client.
Successfully added 'AsyncModule.NetMQ 1.1.0' to NuGet.Client.
You can also use the graphical interface to find theManager NuGet Package For Solution...
Open graphical interface, Click Install on the right side of the library package to be installed, It's the same as entering commands.

The list on the left side of the interface contains installed library packages, On-line, Filter such as update, Online classification according to data sources. In the middle is the current data source library package list, On the right is the search bar and the details of the selected library package.

When the dependency package is installed, we can find it in the root directory of the projectpackages.config file, The library package and version information we installed will be recorded

At the same time, there will be apackages The folder of is used to save the library package we downloaded

MakeNuGet Library package

If we need to upload ourdll reachNuGet Server, First of all, let'sVS Export at compile timeNuGet Supported by.nupkg file
Right click on the solution to findEnable NuGet Package Restore Click to open the function

After opening, we need to manually.csproj In filePropertyGroup Add the following nodes below
<BuildPackage>true</BuildPackage> <RestorePackages>true</RestorePackages>

At the same timeProject Add the following content in the node
<Import Project="$(SolutionDir)\.nuget\NuGet.targets"
Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" /> <Target
Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup> <ErrorText>This project references NuGet package(s) that are
missing on this computer. Enable NuGet Package Restore to download them. For
more information, see The
missing file is {0}.</ErrorText> </PropertyGroup> <Error
'$(SolutionDir)\.nuget\NuGet.targets'))" /> </Target>

Recompile the project and it will be automatically compiled.nupkg file.

If it is.Net Standard The project can be packaged directly by right clicking the program.

buildNuGet The server

Create a new project

Use here3.0 VersionsNuGet.Server, Need.Net Framework 4.6 Support.
Then quoteNuGet.Server Library package
PM> Install-Package NuGet.Server
After installation, Compile and start, It's that simple, Then hosting toIIS upper.

You may need to upload the library packageapikey, Need toweb.config Set in.

uploadNetGet Library package

CompileNuGet We need to upload the package toNuGet Server, So that we canVS Middle slaveNuGet Download it from the server. Here I useNuGet Package Explorer
Tools to upload, Official supportWin10 Store and useChocolatey download.
Upload toNuGet The official server canNuGet Official website <>
upload, But we usually need to upload to the specifiedNuGet Server, Like our ownNuGet The server.

Select the first item to find the local.nupkg file

You can compile the information on the left,

When multiple versions ofdll,NuGet.Server According to the packageId andVersion Grouping

You can use theTAB Key intelligent prompt all current version numbers

We can also upload by command
nuget.exe push {package file} {apikey} -Source

When we upload the same version of the same package, an error will be reported when we upload it again, We need to deleteNuGet.Server Existing package, Upload again after. Or we can allow the same version of the package to be overwritten and uploaded, take
web.Config OfallowOverrideExistingPackageOnPush Configuration changed totrue that will do

Newly addedNuGet source

stayTools-Options-NuGet Package Manager-Package Sources Data sources can be added

Click the plus sign in the upper right corner to add, Click Update after entering the address.


This article explains how to use, deployNuGet, How to compile build, Upload library package toNuGet.

Address of this article:
Author blog: Jay is busy.
Welcome to reprint, Please provide the source and link in an obvious place