Neo
Neo

Reputation: 16239

which is good approach to create nuget packages?

As I developer I wonder which is the best approch to create a nuget packages ?

1.NuGet Package Project (link)

2.Use Nuget.exe use .Nuspec (add manually and update manually)

Anyone guide on this. Currently I'm using nuget.exe and .Nuspec but problem is everytime I have to manually update .nuspec if any new project is added.

Is there any other good options to do so ?

Upvotes: 0

Views: 767

Answers (3)

Ian Brown
Ian Brown

Reputation: 1

I'm new to developing nuget packages, (and posting on Stack Overflow). I started using the nuget.exe command-line approach, which I learned about: here. But from what I've gathered so far, there is a convention of using .NET Standard, instead of .NET Framework when developing nuget packages. Especially on nuget.org. So, when developing a .NET Standard class library, check out the project properties under the project tab in Visual Studio. There you will see multiple tabs on the left, starting with build. Click on the Package tab. Now you'll see a great way to enter all properties that you would normally have to do manually when trying to create the .nuspec file. You'll want to be sure to fill it out completely to avoid flags when uploading to nuget or wherever. Create your repository and file in github, and enter their URLs. Also, imgur.com is a great place to host your icon image. Be sure to click the Generate Nuget Package checkbox. Voila! Now build your library and you'll notice a .nupkg file. This is the best resource.

Upvotes: 0

Narottam Goyal
Narottam Goyal

Reputation: 3652

Create nuget package in the following manner

  1. Download nuget.exe from here https://www.nuget.org/
  2. Create empty spec file (execute below command under project root folder)

    nuget spec

  3. Update nuget spec file SomeLib.nuspec according to your library properties(use any text editor)

  4. Create some folders nugetPack/lib/net46/ and then paste the dll here; which you want to make as nuget package

  5. Create nuget package (execute below command under project root folder)

    nuget pack -basepath nugetPack SomeLib.nuspec

Now use this nuget package in your project

  1. Set the nuget package source which you have created
  2. Goto Visual Studio > Tool > NuGet Package Manager > Package Sources > here add your nuget package source folder path
  3. Right click and select managae nuget packages on the project where you want to consume nuget package.
  4. Select the right package source from the top right drop down box.
  5. search your nuget package and install.

Another cool way to create nuget package via NuGet Package Explorer which you can download it from here https://npe.codeplex.com/ then just simply fill the form and save the nuspec file to your local nuget package source folder.

Sample nuspec file whihc has some dependencies

<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
    <metadata>
        <id>your.package.name</id>
        <version>1.0.0</version>
        <title>package title</title>
        <authors>NG</authors>
        <owners>NG</owners>
        <requireLicenseAcceptance>false</requireLicenseAcceptance>
        <description>some description</description>
        <summary>some summary</summary>
        <copyright>open</copyright>
        <language>en-US</language>
        <tags>your package keyboards</tags>
        <dependencies>
            <dependency id="Microsoft.AspNet.WebApi.Core" version="5.2.3" />
            <dependency id="Microsoft.AspNet.WebApi.Client" version="5.2.3" />
            <dependency id="Newtonsoft.Json" version="9.0.1" />
        </dependencies>
    </metadata>
</package>

Github README

Upvotes: 0

hsirah
hsirah

Reputation: 347

You can also build a NuGet package by running the nuget pack command against the csproj file. More information can be found here: Creating And Publishing A Package

Upvotes: 1

Related Questions