这些是我们在项目中生成 NuGet 包所遵循的步骤-
1.下载Nuget.exe并将其放在.csproj文件所在的文件夹中。
2.打开cmd并输入nuget spec。将创建带有.nuspec 扩展名的文件。
3.打开创建的文件并添加标签:
<files> <file src="..\..\SomeRoot\**\*.*" target="libs\net461" /> </files>
4.在cmd中执行nuget pack A.csproj –IncludeReferencedProjects。扩展名为 .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 pack 命令示例供您参考 -
"scripts": {
"postcompile": [
"dotnet pack --no-build --configuration %compile:Configuration%"
]
}