In my project I reference some packages with PackageReference
like that:
But, if I run pack command, it doesn't include them unless I manually add them 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:
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.
NuGet Package ManagerSelect Project > Manage NuGet Packages. In the NuGet Package Manager page, choose nuget.org as the Package source. From the Browse tab, search for Newtonsoft.Json, select Newtonsoft.Json in the list, and then select Install. If you're prompted to verify the installation, select OK.
To create a NuGet package from your project, follow these steps: Select Build > Configuration Manager, and then set the Active solution configuration to Release. Select the AppLogger project in Solution Explorer, and then select Build > Pack. Visual Studio builds the project and creates the .nupkg file.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With