NuGet is an open source project that includes NuGet vs plugin/nuget explorer/nugetserver/nuget command line Projects , and. NET core projects using NuGet entirely Managing dependencies between components, NuGet has become an integral part of the. NET ecosystem, from a project perspective, to the various components in the project to NuGet, add components/Remove components/and update components to complete a key, greatly improve productivity, Reduce unnecessary citation errors. from an operational perspective, a new version can be released without affecting the old version, unifying the use of components in different versions of the company's various projects and the components of each version, reducing the occurrence of failures and making the project run stably.
Used to do NuGet package we generally either use the command line, or use the NuGet graphical interface to do, but some of the operation is more troublesome. For example, introduce a namespace to introduce a third-party NuGet package. These are very simple in the. NET core project, just need to use the command line dotnet Pack, in the. NET Core series: 1,. NET core Environment Building and command line CLI Introduction to do a brief introduction, the following we will detail the next command.
dotnet-pack-Package your code as a NuGet package
Overview
dotnet pack [--output] [--no-build] [--build-base-path] [--configuration] [--version-suffix] [<project>]
Description
dotnet packcommand to build the project and create a NuGet package. The result of this operation is a two nupkg -extension package. One contains the code and the other contains the debug symbol.
The project is dependent on the NuGet wrapper that is added to the Nuspec file, so they can be resolved when the package is installed.
By default, project-to-project references are not packaged into projects. If you want to do that, you need to refer to the node in your dependencies that requires the project to be type set to "build", as in the following example:
{ "version": "1.0.0-*", "dependencies": { "ProjectA": { "target": "project", "type": "build" } }}
By default, the dotnet pack project is built first. If you want to avoid this, pass the --no-build option. This is useful in the continuous integration (CI) build scenario, as you know that the code is just a pre-built example.
Options
[project]
Packaged items. It can also be a project.json path to a file or a directory. If omitted, it defaults to the current directory.
-o, --output [DIR]
Specifies the generated directory.
--no-build
Skip the build phase in the packaging process.
--build-base-path
Specifies the catalog of temporary build artifacts. By default, they are in the obj directory of the current directory.
-c,--configuration [Debug|Release]
The configuration that is used when the project is built. If not specified, the default is "Debug".
Example
dotnet pack
Package the current project.
dotnet pack ~/projects/app1/project.json
Package The APP1 project.
dotnet pack --output nupkgs
Packages the current application and places the resulting package in the specified folder.
dotnet pack --no-build --output nupkgs
Package the current project into the specified folder and skip the build step
Back to our in. NET Core series: 3, use multiple projects to create a class library project Dotnetnewlib, switch to the Dotnetnewlib directory to execute the dotnet Pack command:
[[email protected] dotnetnewlib]# dotnet Pack
Project Dotnetnewlib (. netstandard,version=v1.6) was previously compiled. Skipping compilation.
Producing NuGet package ' dotnetnewlib.1.0.0 ' for Dotnetnewlib
Dotnetnewlib-/root/dotnetnewlib/bin/debug/dotnetnewlib.1.0.0.nupkg
Producing NuGet package ' dotnetnewlib.1.0.0.symbols ' for Dotnetnewlib
Dotnetnewlib-/root/dotnetnewlib/bin/debug/dotnetnewlib.1.0.0.symbols.nupkg
The directory structure is as follows:
Dotnetnewlib
|--Library.cs
|--Project.json
|--Project.lock.json
+-bin
+-debug
|--dotnetnewlib.1.0.0.nupkg
|--dotnetnewlib.1.0.0.symbols.nupkg
+--netstandard1.6
|--DotnetNewLib.deps.json
|--DotnetNewLib.dll
+--dotnetnewlib.pdb
In the above structure I took the obj directory off, we saw in the debug directory generated 2 files dotnetnewlib.1.0.0.nupkg and dotnetnewlib.1.0.0.symbols.nupkg, these are nuget packages, very simple , the version number information is from the Project.json file:
{
"Version": "1.0.0-*",
"Buildoptions": {
"Debugtype": "Portable"
},
"Dependencies": {},
"Frameworks": {
"netstandard1.6": {
"Dependencies": {
"Netstandard.library": "1.6.0"
}
}
}
}
But I generated the debug, we generated release version:
dotnet Pack-c Release
[Email protected] dotnetnewlib]# dotnet pack-c Release
Project Dotnetnewlib (. netstandard,version=v1.6) 'll be compiled because expected outputs is missing
Compiling dotnetnewlib for. netstandard,version=v1.6
Compilation succeeded.
0 Warning (s)
0 Error (s)
TIME Elapsed 00:00:03.4976986
Producing NuGet package ' dotnetnewlib.1.0.0 ' for Dotnetnewlib
Dotnetnewlib-/root/dotnetnewlib/bin/release/dotnetnewlib.1.0.0.nupkg
Producing NuGet package ' dotnetnewlib.1.0.0.symbols ' for Dotnetnewlib
Dotnetnewlib-/root/dotnetnewlib/bin/release/dotnetnewlib.1.0.0.symbols.nupkg
The release directory was generated
Dotnetnewlib
|--Library.cs
|--Project.json
|--Project.lock.json
+-bin
+-debug
|--dotnetnewlib.1.0.0.nupkg
|--dotnetnewlib.1.0.0.symbols.nupkg
+--netstandard1.6
|--DotnetNewLib.deps.json
|--DotnetNewLib.dll
+--dotnetnewlib.pdb
+-release
|--dotnetnewlib.1.0.0.nupkg
|--dotnetnewlib.1.0.0.symbols.nupkg
+--netstandard1.6
|--DotnetNewLib.deps.json
|--DotnetNewLib.dll
+--dotnetnewlib.pdb
2 files were generated in the release directory Dotnetnewlib.1.0.0.nupkg and Dotnetnewlib.1.0.0.symbols.nupkg, and the first file was the NuGet package we wanted. Let's look at the specifics of the NuGet package and we can use
The NuGet package Explorer tool opens dotnetnewlib.1.0.0.nupkg:
There is only one lib file netstandard1.6 the target configuration file. This means that our NuGet package applies only to. NET core applications for NetStandard1.6 (and upcoming 4.6.3), articles embracing. NET core, how to develop a cross-platform class library (1)
The NuGet package is well illustrated, recommended for everyone to read, and the garden has a "nuget package created with command-line tools" to explain the details of NuGet.
. NET Core Series 5: Using NuGet to package class libraries