如何从 project.json 构建 nuget 包?

How can I build a nuget package from project.json?

我正在寻找从我的源构建 nuget 包的最简单方法。我有 Visual Studio 2015 Update 3,我的解决方案有一个 .NET Core Class 库项目(基于 project.json)。我正在尝试从该项目创建一个包。目前为了能够这样做,我创建了一个 .nuspec 文件并手动编辑它,即复制了我的 project.json 文件中列出的所有依赖项。

除了手动创建和编辑 .nuspec 文件之外,还有更好的方法吗?如果我在 project.json 中进行更改,我还必须将它们反映在 .nuspec 文件中,这听起来很奇怪。

顺便说一句,这个 guide 对我不起作用,因为没有 'Produce outputs on build' 复选框

尽管安装了 Microsoft ASP.NET 和 Web 工具

我是不是漏掉了什么?

这些是我们在项目中生成 NuGet 包所遵循的步骤-

1.Download Nuget.exe 并将其放在 .csproj 文件所在的文件夹中。

2.Open 命令并输入 nuget spec。将创建扩展名为 .nuspec 的文件。

3.Open 创建的文件并添加标签:

<files> <file src="..\..\SomeRoot\**\*.*" target="libs\net461" /> </files>

4.Execute nuget pack A.csproj –IncludeReferencedProjects 在 cmd 中。已创建扩展名为 .nupkg 的文件。

5.Go 到 visual studio。在 NuGet 包管理器设置中,添加“包源”并提供 .nupkg.nuspec 文件所在的路径。

6.Close Nuget 包管理器并再次打开它。现在您可以在浏览选项卡下创建的包源中找到它。

注意:您的 .nuspec 文件应如下所示:

<?xml version="1.0"?>
<package  xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <metadata  xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
    <id>ABC.XYZ.FL</id>
    <version>1.0.0.0</version>
    <title>ABC.XYZ.FL</title>
    <authors>ABC</authors>
    <owners>ABC</owners>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <description>Framework that will be used to create objects in XYZ world</description>
    <releaseNotes>Summary of changes made in this release of the package.</releaseNotes>
    <copyright>2016</copyright>
    <tags>ABC.XYZ.FL</tags>
  </metadata>
  <files>
    <file src="bin\Debug\*.dll" target="lib\net461" />
  </files>
</package>

以下链接包含有关创建 nuget 包并在本地托管它的更多详细信息:

https://docs.nuget.org/create/creating-and-publishing-a-package

https://docs.nuget.org/create/hosting-your-own-nuget-feeds

https://docs.nuget.org/consume/nuget-config-file

看看这是否有帮助。


编辑:

这里有 dotnet pack 命令示例供您参考 -

"scripts": {
  "postcompile": [
    "dotnet pack --no-build --configuration %compile:Configuration%"
  ]
}