Note: This article mainly references (setting up nuget servers internally) and (introducing the use of nuget in traditional Asp.net projects). It is just a simple introduction. This article provides some supplements, it is more suitable for new friends who are new to nuget. I would like to thank the original author for sharing this article.
1. What is nuget?
Nuget (http://nuget.codeplex.com) is an open source package manager that makes it easier to add some DLL and files (such as jquery) to a project without the need to copy from the file. For a simple example, if you want to add jquery1.5.2 to the project, you do not need to download it from the official website after using nuget, and then manually add it to the project, you can run the "Install-package jquery 1.5.2" command.
The official website (http://nuget.codeplex.com) has provided a lot of openSource codePackage, we can add reference directly, or we can put our ownCodeNot only that, but we can set up our own (or internal company) nuget server and put our own private code on the server. We can simply add it with nuget when necessary.
2. Experience nuget
First install the nuget plug-in Vs and open tools> Extension Manager:
Find and install nuget:
Open a Web project and open the Package Manager Console window:
Now you can try nuget's powerful functions. Enter install-package jquery In the Package Manager Console:
Note that the pack source option is the official code source, which is the default one. We can add our own code source as shown in the following figure. Now let's take a look at the scripts folder of the Project. Has jquery added the latest version.
3. Set up your own (or internal company) nuget Server
Download nugetserver.zip, a server that uses mvc3, and provides a page for browsing and uploading packages.
Decompress the project, use vs (vs2010) to open and compile the project, and then publish it to the Intranet server. It is worth noting that the code in the nugetserver.rar package where the nuget server is set up internally is a bit problematic, that is, global in MVC. asax. the routing configuration information of CS and app_start/registermvc3routes. CS already exists. You need to comment out one. I have commented out global. asax. in CS:
After compilation, it is published to IIS. Here, it is published to the Local Machine (or to the server. If it is set up inside the enterprise, it is best to publish it to the internal server of the enterprise ), the configuration in IIS is as follows:
Here, the host name can also be added with localhost. I personally prefer the domain name form. If you want to configure the domain name in the figure, change the route in the hosts file:
Then find the application you added when adding the website.ProgramTo change the. NET Framework version to 4.0:
Now you can browse the website:
The above is the server-side configuration. When you see this page, it indicates OK.
4. Package the code into a nuget package
First, download the nuget command line from codeplex:
There are two packaging methods for this tool:
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 (this is also applicable to a single DLL. The following uses a single dll as an example ):
Place the DLL to be packaged with nuget.exe in a directory and use the nuget spec command to create a nuspec file. This is an XML file:
Open the package. nuspec file to customize some configurations. It is important to add the DLL information to be packaged:
Then pack it into a nuget package using the nuget Pack:
Packaging is complete now
5. Upload the nuget package to the server
In step 2, upload the website you have configured:
Click the here link on the page to view the nuget package on the current server:
Note: In the article "setting up nuget servers internally", the author wrote an upload tool. If you are interested, you can check it out.
6. Use it in other projects
So far, the server has been configured, and the packaging of the class library and DLL files has been completed. The following is how to use it in other projects.
To use it in a project, add your own code source as follows:
1. Go to package manager settings:
2. add our own code source:
Pay attention to source, followed by nuget.
3. Open the Package Manager Console in other projects, select the code source we added above, and then call:
4. Finally, let's look at the effect:
OK. You are welcome to leave a message for discussion.