To package a NuGet package using the command line

Source: Internet
Author: User

For those of you who are not going to be involved in this complex and want to make their own nuget packages, I recommend using the NuGet package Explorer. About the use of this graphical NuGet package management software, there are related articles in the blog park, you can search to see.

Okay, back to the chase. But we all know that the biggest problem with graphics is the low level of automation .

This is one of my nuget package, you can see the file is still relatively many, then every time I recompile, need to publish a new version of the time, you have to replace most of the files inside the new file. Every time a replacement of one, annoying ah. And sometimes you have to worry about having fewer replacements. Then automated packaging is certainly worth studying.

On the NuGet website we can find a tutorial on how to create a NuGet package: Https://docs.nuget.org/Create/Creating-and-Publishing-a-Package.

So let's download this command-line tool first.

Then prepare the files that we need to pack (that is, DLLs, etc.).

Read the following document, said is to support read direct csproj file packaging, then we try it, after all, the code of the programmer is simple, can lazy on lazy.

Here my project structure is this:

Then we run CMD and enter the command

Make a mistake, regenerate the project and run again.

Looks like a look at the catalogue.

But this DLL belongs to the classification, wrong, I built the WIN10 application DLL ...

Since the csproj scheme is not working, we continue to read the document. See there's a scenario by describing the NuGet package: https://docs.nuget.org/Create/Creating-and-Publishing-a-Package#create-the-manifest

It's easy to create a profile, run a command

Then we use a text editor to open this new Package.nuspec file.

You can see that it is an XML file and then modify the properties underneath it.

Execute again.

There is a warning, a simple look, is that you do not know which files should be packaged.

So keep looking for documents, and finally we can find this.

Modify our Nuspec file below.

The new red part, which is to pack the DLL into the Lib\uap10.0\ directory of the NuGet package.

Execute the package command again.

There's no warning this time.

And the structure of the package is no problem.

Then just write the files node inside Nuspec, then execute nuget pack xx.nuspec This command, you can simply generate NuGet package.

In order to be lazy again, we will handle the above command in batches.

%~dp0nuget.exe Pack%~dp0package.nuspec-outputdirectory%~dp0

%~dp0 This is the directory where the bat file is currently executing.

Then it turns out that:

Make sure that the three files are put together, and then execute package.bat to generate the NuGet package in the current directory.

Next we can release the NuGet package, with the command line, but to protect a little, I still use GUI tools to publish (after all, after the release of the review is necessary).

Open the NuGet package created above with the NuGet packages Explorer.

Just click here to do it.

Note: Once released, the package on NuGet is not able to be deleted!! Can only be hidden, so make sure to publish again without error.

Here is the split line:

To the last step we have done with batch processing, then we can play more tricks, such as PowerShell to automate the version of the package. In the project AssemblyInfo.cs there is a assemblyversion Attribute, then we can use PowerShell to read this version number first, and then modify the Nuspec file in the versions node, regenerated into a package. In fact, I have done so now, because I have not learned PowerShell, the code will not let out the humiliation. You can think out of your mind and expect to see your friends ' packages on nuget.

To package a NuGet package using the command line

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.