* preface < preface >
* What is? NuGet? < What is? nuget>
* Why use NuGet < Why use nuget>
* NuGet Advantages of < Advantages of >
* use < use >
* Get-Help NuGet
* Install-Package
* Get-Package <>
* Uninstall-Package
* make NuGet Library package < make nuget Library package >
* build NuGet The server < build nuget The server >
* upload NetGet Library package < upload netget Library package >
* newly added NuGet source < newly added nuget source >
* summary < summary >

What is? NuGet?

Nuget It's a .NET Open source projects under the platform , It's Visual Studio Extension of . in use Visual Studio Development based on .NET
Framework Application of ,Nuget Can add to the project , Removing and updating references is faster and easier .

Why use NuGet

If our project development does not need to refer to any third-party library package or our own public library package , Then use NuGet No use , 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 use Kernal And other libraries may not be the same version , Even if it's the same version, we always develop the dll 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 of

take AsyncModule.NetMQ.dll give an example ,AsyncModule.NetMQ.dll rely on NetMQ.dll, and NetMQ.dll And rely on
At present, where we need database connection, we need to reference AsyncModule.NetMQ.dll, We may bake it by hand into the project we need , But because
AsyncModule.NetMQ.dll Need to rely on NetMQ.dll, So we also need to hand NetMQ.dll Copy to our project , At the same time, due to NetMQ.dll Need to rely on
AsyncIO.dll, So we also need to hand AsyncIO.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 the dll, meanwhile NuGet
Will automatically reference its dependent packages together into our project , It's completely automatic .


stay VS Found in Package Manager Console dialog box

If not found on the interface , From tools -NuGet Package Manager Down looking

Get-Help NuGet

use Get-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

use Install-Package Install library package , Automatically install the current Framework 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


use Get-Package Install library package
PM> Get-Package Id Version Description/Release Notes -- -------
------------------------- AsyncIO AsyncIO AsyncModule.NetMQ 1.1.0
be based on NetMQ Asynchronous of Socket frame NetMQ A 100% native C# port of the lightweight high
performance messaging library ZeroMQ

use Uninstall-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 the Manager 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 project packages.config file , The library package and version information we installed will be recorded

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

make NuGet Library package

If we need to upload our dll reach NuGet In server , First of all, let's VS Export at compile time NuGet Supported .nupkg file
Right click on the solution to find Enable NuGet Package Restore Click to open the function

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

At the same time Project 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 .

build NuGet The server

Create a new project

Used here 3.0 Version of NuGet.Server, need .Net Framework 4.6 support .
Then reference NuGet.Server Library package
PM> Install-Package NuGet.Server
After installation , Compile and start , It's that simple , Then hosting to IIS upper .

You may need to upload the library package apikey, Need to be in web.config Setting in .

upload NetGet Library package

Compiled NuGet We need to upload the package to NuGet In server , So that we can VS From NuGet Download it from the server . Here I use NuGet Package Explorer
Tools to upload , Official support Win10 Store and use Chocolatey download .
Upload to NuGet The official server can NuGet Official website <>
upload , But we usually need to upload to the specified NuGet On the server , Like our own NuGet The server .

Select the first item to find the local .nupkg file

You can compile the information on the left ,

When multiple versions of dll,NuGet.Server According to the package Id and Version Group

You can use the TAB 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 delete NuGet.Server Existing package , Upload again after . Or we can allow the same version of the package to be overwritten and uploaded , take
web.Config Of allowOverrideExistingPackageOnPush Configuration changed to true that will do

newly added NuGet source

stay Tools-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 , deploy NuGet, How to compile build , Upload library package to NuGet.

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