misticos
misticos

Reputation: 797

Auto-add PackageReferences to NuGet package

In my project I reference some packages with PackageReference like that:

My PackageReference

But, if I run pack command, it doesn't include them unless I manually add them to .nuspec file.

Adding references to nuspec file

I want to automatically add packages from PackageReference in my C# project to NuGet packages.

I pack my project using nuget pack ProjectFile on Build or manually.

Current nuspec with dependencies:

NuSpec with dependencies

P.S. AFAIK references from packages.config are automatically added, but I don't want to use this file. I want to use PackageReferences instead.

Upvotes: 9

Views: 2631

Answers (1)

Roman Marusyk
Roman Marusyk

Reputation: 24609

Actually, you don't need .nuspec file anymore. All information you can specify in csproj file like:

<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>

Then I've added this line into csproj.

<GeneratePackageOnBuild>true</GeneratePackageOnBuild>

To build it I use:

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

It works in my case without define any dependencies

Upvotes: 4

Related Questions