如何从project.json构建nuget包?
我正在寻找从我的来源构建Nuget包的最简单方法。我有Visual Studio 2015 Update 3,我的解决方案有一个.NET Core Class Library Project(基于project.json)。我正在尝试从该项目创建一个包。目前为了能够这样做,我创建了一个.nuspec文件并手动编辑它,即复制列在我的project.json文件中的所有依赖项。如何从project.json构建nuget包?
除了手动创建和编辑.nuspec文件之外,还有更好的方法吗?如果我在project.json中进行了更改,我还必须在.nuspec文件中反映它们,这听起来很奇怪。
顺便说一句,这guide不适合我,因为没有 '生产上生成输出' 复选框
虽然安装了Microsoft ASP.NET和Web Tools
我错过了什么吗?
这些都是我们遵循我们的项目产生的NuGet步骤套餐的
1.Download Nuget.exe
,并将其放置在那里.csproj
文件所在的文件夹中。
2.打开cmd并输入nuget spec
。带有.nuspec
扩展名的文件将被创建。
3.Open创建的文件,并添加标签:
<files> <file src="..\..\SomeRoot\**\*.*" target="libs\net461" /> </files>
4.Execute nuget pack A.csproj –IncludeReferencedProjects
在cmd中。带有.nupkg
扩展名的文件被创建。
5.转到视觉工作室。在NuGet程序包管理器设置中,添加“程序包源代码”并提供您的文件存在.nupkg
和.nuspec
的路径。
6.关闭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包命令样本 -
"scripts": {
"postcompile": [
"dotnet pack --no-build --configuration %compile:Configuration%"
]
}
没有。 csproj文件。相反,project.json用于列出所有依赖关系的地方。我的问题是,我正在寻找一种避免手动复制依赖关系的方法。 nuspec文件,当他们改变。 – neleus
您是否尝试过'dotnet pack'命令? – Sanket
哦,我是对的,我错过了这个!谢谢。你可以改正你的答案,然后我可以接受它。 – neleus