Original address
Https://docs.microsoft.com/zh-cn/dotnet/articles/core/deploying/creating-nuget-packages
Content
For. NET Core 1.0, all libraries should be published as NuGet packages. In fact, this is how all. NET Standard libraries are published and used. This can be done dotnet pack
easily with commands.
Let's say you've just written a great new library and want to publish it through NuGet. You can use the cross-platform tool to create a NuGet package, and do exactly as you please! The following example assumes that a library named Superawesomelibrary is used netstandard1.0
as the target.
If there are transitive dependencies, that is, if one project relies on another project, you need to make sure that you use the package that restores the entire solution before you create the NuGet package dotnet restore
. Failure to do so will cause the dotnet pack
command to not function properly.
After you confirm that the package has been restored, you can navigate to the directory where the library is located:
$ CD Src/superawesomelibrary
Then, just enter a command on the command line:
$ dotnet Pack
/bin/Debug
The folder now looks like this:
$ ls bin/Debugnetstandard1. 0/superawesomelibrary. 1.0. 0 . Nupkgsuperawesomelibrary. 1.0. 0. symbols.nupkg
Note that this will generate a package that can be debugged. If you want to build a NuGet package with a binary version, simply add -c
/ --configuration
switch and use release
as a parameter.
$ dotnet Pack--configuration release
/bin
The folder will now contain a release
folder that contains the NuGet package as a binary file version:
$ ls bin/releasenetstandard1. 0/superawesomelibrary. 1.0. 0 . Nupkgsuperawesomelibrary. 1.0. 0. symbols.nupkg
Therefore, it is now possible to publish the NuGet package with this required file!
Do not confuse dotnet pack
anddotnet publish
It is important to note that not all times involve dotnet publish
commands. dotnet publish
commands are used to deploy applications with all dependencies in the same package-not to build NuGet packages that are published and used by NuGet.
How to create a NuGet package with cross-platform tools (GO)