哪个是创建 nuget 包的好方法?

which is good approach to create nuget packages?

作为开发人员,我想知道创建 nuget 包的最佳方法是什么?

1.NuGet Package Project (link)

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

任何人对此进行指导。 目前我正在使用 nuget.exe.Nuspec 但问题是每次我必须手动更新 .nuspec 如果添加任何新项目。

还有其他好的选择吗?

您还可以通过 运行 nuget pack 命令针对 csproj 文件构建 NuGet 包。可以在此处找到更多信息:Creating And Publishing A Package

Create nuget package in the following manner

  1. 从这里下载 nuget.exe https://www.nuget.org/
  2. 创建空规范文件(在项目根文件夹下执行以下命令)

    nuget 规范

  3. 根据您的库属性更新 nuget 规范文件 SomeLib.nuspec(使用任何文本编辑器)

  4. 创建一些文件夹nugetPack/lib/net46/,然后将dll粘贴到这里;你想制作成 nuget 包

  5. 创建nuget包(在项目根文件夹下执行以下命令)

    nuget pack -basepath nugetPack SomeLib.nuspec

Now use this nuget package in your project

  1. 设置你创建的nuget包源
  2. 转到 Visual Studio > 工具 > NuGet 包管理器 > 包源 > 在这里添加你的 nuget 包源文件夹路径
  3. 在要使用 nuget 包的项目上右键单击并 select managae nuget 包。
  4. Select右上角下拉框中的正确包源。
  5. 搜索你的 nuget 包并安装。

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

我是开发 nuget 包的新手(并在 Stack Overflow 上发帖)。我开始使用 nuget.exe 命令行方法,我了解到: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 是最好的资源。