Introduction to nuget's use in traditional Asp.net Projects

Source: Internet
Author: User

Recently I learned a lot about nuget and watched many of its videos, especially those on mix11.

If we want to judge a star on mix11, you may think it is WP7 or sl5. Then you must be wrong. The star must be nuget. Because almost every Microsoft speaker is using nuget. Why is it so popular ?? It improves the efficiency and ease of use.

 

If you go to Google to describe nuget, you will find the results as follows:

Almost noneArticleAnd many of them are reprinted from the article I wrote. I am not a bad man in the Declaration... I think that if many people use it, I don't have to bother writing it again. In particular, many people explain how it is used in the Asp.net MVC project. It is also useful in traditional Asp.net projects.

For the basic introduction of nuget, you can search for the articles I wrote by myself, so I will not give link.

 

Before performing the exercises, create an empty Asp.net solution (not MVC)

 

 

1. Add a third partyCodeUse of packages

The traditional method of adding a DLL is to download, decompress, find the DLL to be added to the project, and add references. It is relatively easy to add a DLL using nuget, first, you can go to nuget.org to check whether there is any third-party software package you want to add. For example, we want to add elmah:

Use the Package Manager Console to add elmah.

 

In addition to adding DLL files, we can also add other files. For example, if I create an empty Asp.net solution, I want to add jquery IN THE WEB Project, the project template comes with 1.4. What should I do if I want to use 1.5 ?? Simply use Install-package elmah.

 

Now, write the jquery script. You can use Install-package jquery. vsdoc to install the latest smart prompt package ..

 

 

2. How to create a local reference

It is easy to create a local reference. For example, if we have added several installation packages, you can see a packages folder in the solution. Use it for local reference.

Click the button shown in To Go To The setting page,

 

Add a local package source named localfeed. The path points to the packages folder mentioned above:

 

 

Find localfeed in package Resource:

 

You can point this path to any place where the nuget package is stored .....

 

 

3. Create your own company's nuget server.

The above method is to use a local resource package, if it is a large company, or your company will provide a server to store internal public DLL for you, the traditional way to add these public DLL files is to use SVN or other source code management tools. You also need to find them first, then download them, and then add references.

If a DLL is updated, all other project teams need to use a new DLL. You have to download it repeatedly, add references, or even delete the original DLL ....

At this time, it is necessary to create a local nuget server.

How can we create it ???????????????????

 

First, create an empty Asp.net project:

 

Then install the nuget. server package, which is available on the feed officially provided by nuget.

 

After the installation, place several nuget packages in the packages folder and access default. aspx:

 

On the packages page, you can see the included nuget package. nuget is an atom feed in the form of odata. For example:

 

 

According toHttp: // localhost: 55326/nuget/Add to your nuget Source:

 

Now you can package the DLL shared by your company into a nuget package and put it in the packages directory of this website.

I have been introducing how nuget's feed is created by myself. How can we package nuget internally ????

4. How to package code into a nuget package

First, download the nuget command line from codeplex:

 

This is a packaging tool. You can use the following two packaging methods:

A. Package the DLL directly through the project file:

Create a class library and compile it. Copy the downloaded nuget.exe file to the folder where the project file is located:

 

Create an nuget package using the command line:

Done:

 

 

B: Use the nuget spec file for packaging:

First, you must create an nuget. spec file:

 

Edit the created spec file in the project:

 

You can edit the nuget package information, such as the author and version...

 

You can also create two folders, content and tools, during packaging.

5. nuget advanced applications (scaffold extension)

This section uses the powershell and T4 templates to automatically create, add, delete, modify, and query instances through a class. I wantSource codePut it on codeplex.

 

Code and introduction: I will share nuget with you next week, and then I will make up the article and code with the PPT ......

 

If you are interested in nuget, follow me and you will be able to see the article updates at any time.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

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.