STEP 1: Register and get API Key
First of all, you need to register a new account with NuGet and then get an API Key on my Accounts page, this process is simple and I won't explain it.
STEP 2: Download NuGet.exe
NuGet has a command-line tool: NuGet.exe; for ease of use, set the PATH environment variable "EXE directory" of the machine and add the paths of NuGet.exe to path.
Find NuGet.exe at the bottom of the http://nuget.codeplex.com/releases page and click Download
STEP 3: Set API Key
CMD to set the NuGet API Key using the following command:
NuGet Setapikey <my_api_key>
Remember to replace the above My_api_key with the API Key obtained in step 1.
STEP 4: Develop your own class library
We created a new class library: Daxnetnugettest and added a reference to Castle.core through NuGet, and now we add some code to use some of the features provided by Castle.core. We renamed Class1.cs to CastleHelper.cs, and the Class1 class was renamed Castlehelper. Write the following code in CastleHelper.cs:
Public class castlehelper{ publicstatic castle.core.pair<intint> Getintpair () { returnnew castle.core.pair<intint > (a);} }
Then, open the AssemblyInfo.cs file, set the properties of the Assembly, and remember to set the AssemblyVersion feature to specify the version of our class library. We currently use the 1.0.0.0 version:
[Assembly:assemblytitle ("daxnetnugettest")][assembly:assemblydescription ("daxnet ' s test of the NuGet.")][assembly:assemblyconfiguration ("")][assembly:assemblycompany ("daxnet")][assembly:assemblyproduct ("daxnetnugettest")][assembly:assemblycopyright ("copyright©daxnet")][assembly:assemblytrademark ("")][assembly:assemblyculture ("")][assembly:comvisible (false)][assembly:guid ("20662b9f-91de-4515-9c8c-ced3d61589e1")][assembly:assemblyversion ("1.0.0.0")]
When all is set up, compile the entire project to be used.
STEP 5: Generate and modify Nuspec
Nuspec is the input file that NuGet packages the project into Nupkg, which can be generated through the NuGet spec command. At the command prompt, enter the directory where the Daxnetnugettest.csproj file is located, and then execute:
You are prompted to create a success:
Open the Daxnetnugettest.nuspec file with Notepad, replace the information you need to replace, do not need to delete all tags, notice the $xxx$ macro inside, These are references to the setting values in AssemblyInfo.cs, which are replaced with the corresponding values in AssemblyInfo.cs when compiling the package. After completing the edits, our Nuspec file is as follows:
<?xml version="1.0"? ><package > <metadata> <id> $id $</id> <version> $version $</version> <ti tle> $title $</title> <authors> $author $</authors> <owners> $author $</owners> <li Censeurl>http://www.apache.org/licenses/license-2.0.html</licenseurl><projecturl>http://apworks.org</projecturl><requireLicenseAcceptance>false</requireLicenseAcceptance> <description> $description $</description> <releasenotes>first Release</releasenotes> <copyright>copyright -</copyright> </metadata></package>
Note two: 1, $description $ use assemblydescriptionattribute value to replace, before generating the package, it is important to remember to compile the project, otherwise you will be prompted $description$ errors found; 2. Releasenotes if not, delete the node directly, if there is, fill in their own content, do not use the default content, otherwise the next generation of warning messages.
STEP 6: Generate a Class library package
Also under the Daxnetnugettest.csproj path, use the following command to generate the NuGet Class library package:
NuGet Pack Daxnetnugettest.csproj
After success, prompt:
Note: Because our project references Castle.core through NuGet, it will be packaged as a dependent component (dependency) into the resulting nupkg file.
In addition, NuGet is packaged using the assembly generated by the default project configuration. If the project is debug by default and you need to package with release, use the following command:
NuGet Pack Daxnetnugettest.csproj-prop Configuration=release
STEP 7: Publish the Class Library package
Now publish the Class library package with the following command:
NuGet push Daxnetnugettest. 1.0. 0.0. nupkg
When you are finished, the following prompt appears:
STEP 8: Test the published Class library package
Create a new console application, right-click on the project, select Manage NuGet Packages, enter daxnetnugettest in the search box, and the package we publish can already be displayed:
Click the Install button, NuGet automatically parses the component dependencies, and then downloads and adds all the required assemblies to the project reference:
Write a little code to test:
class program{ staticvoid Main (string[] args) { var pair = DaxnetNugetTest.CastleHelper.GetIntPair (); Console.WriteLine (pair. first); Console.WriteLine (pair. Second);} }
The output is as follows:
STEP 9: Update the Class library package
As the class library development progresses, there is bound to be a version update. Updating the class library package is simple, just update the version number in AssemblyInfo.cs and then re-execute step 6, 7 above. Note that when you execute step 7, the nupkg file name should use the new version of the filename.
Now, we reopen the Daxnetnugettest project, change the 20,30 in the Castlehelper class to 40, 50, and then open AssemblyInfo.cs, the version number to 2.0.0.0, recompile the project, and regenerate, Release nupkg:
Open the console program for testing again, and also open the Manage NuGet Packages dialog box, which we can see in updates, Daxnetnugettest has an update:
Click the Update button to update the class library to the latest version. To rerun this console program, we found that the output is already the latest version of the value:
STEP 10: Delete a published package
In principle, NuGet does not allow users to delete published packages, but can only set them to not appear in the list of manage NuGet packages. After you open www.nuget.org and sign in with a registered account, you can select the Manage my Packages link on the My Accounts page to access the Admin page:
After entering, you can see the packages we have published:
Click on the small Trash can icon to the left of Daxnetnugettest to enter the listing page, we can also see "permanently deleting packages is not supported" prompt. To remove the package from the package list, simply remove the hook in front of the list daxnetnugettest 2.0.0.0 in search results option and click the Save button to save:
Original: http://www.cnblogs.com/daxnet/archive/2013/05/07/3064577.html
Use NuGet to publish your own class library package