自动将 PackageReferences 添加到 NuGet 包

mis*_*cos 5 c# dependencies package nuget

在我的项目中,我引用了一些这样的包PackageReference

我的包裹参考

但是,如果我运行 pack 命令,除非我手动将它们添加到.nuspec文件中,否则它不会包含它们。

添加对 nuspec 文件的引用

我想将PackageReferenceC# 项目中的包自动添加到 NuGet 包。

我使用nuget pack ProjectFileon Build 或手动打包我的项目。

当前具有依赖项的 nuspec:

具有依赖项的 NuSpec

PS AFAIK 引用来自packages.config自动添加,但我不想使用此文件。我想用PackageReferences

Rom*_*syk 4

实际上,您不再需要 .nuspec 文件。您可以在 csproj 文件中指定的所有信息,例如:

<PropertyGroup>
    <TargetFrameworks>netstandard2.0</TargetFrameworks>
    <PackageId>BinaryTree</PackageId>
    <Version>5.1.0.0</Version>
    <Authors>RMarusyk</Authors>
    <Description>Simple Binary Tree implementation</Description>
    <PackageProjectUrl>https://github.com/Marusyk/BinaryTree</PackageProjectUrl>
    <PackageTags>binarytree</PackageTags>
</PropertyGroup>
Run Code Online (Sandbox Code Playgroud)

然后我将此行添加到 csproj 中。

<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
Run Code Online (Sandbox Code Playgroud)

为了构建它,我使用:

dotnet build -c Release src/Solution.sln
dotnet pack -c Release src/Solution.sln
dotnet nuget push ..
Run Code Online (Sandbox Code Playgroud)

它适用于我的情况,无需定义任何依赖项