gpt4 book ai didi

c# - 自动将 PackageReferences 添加到 NuGet 包

转载 作者:行者123 更新时间:2023-11-30 21:27:56 29 4
gpt4 key购买 nike

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

My PackageReference

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

Adding references to nuspec file

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

我在构建时使用 nuget pack ProjectFile 或手动打包我的项目。

当前具有依赖关系的 nuspec:

NuSpec with dependencies

附言packages.config 中的 AFAIK 引用会自动添加,但我不想使用此文件。我想改用 PackageReferences

最佳答案

实际上,您不再需要 .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>

然后我将这一行添加到 csproj 中。

<GeneratePackageOnBuild>true</GeneratePackageOnBuild>

为了构建它,我使用:

dotnet build -c Release src/Solution.sln
dotnet pack -c Release src/Solution.sln
dotnet nuget push ..

它在我的例子中没有定义任何依赖项就可以工作

关于c# - 自动将 PackageReferences 添加到 NuGet 包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57009958/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com