Originally posted on: http://geekswithblogs.net/SoftwareDoneRight/archive/2017/10/26/.net-corendashpush-nuget-package-after-build.aspx
You can configure .NET Core to automatically push your nuget package to the package server of your choice by adding a Target to your project file.
1) If your package server requires an api key, you can set it by calling
nuget.exe SetApiKey <YourKey>
2) Add the following target to your csproj file. This sample is configured to only fire on Release Builds.
<Target Name="PushTarget" AfterTargets="Pack" Condition=" '$(Configuration)' == 'Release'">
<Message Importance="High" Text="This is a test After Build Target-->$(TargetPath)" />
<GetAssemblyIdentity AssemblyFiles="$(TargetPath)">
<Output TaskParameter="Assemblies" ItemName="AssemblyVersion" />
</GetAssemblyIdentity>
<Exec Command="dotnet nuget push $(TargetDir)..\$(TargetName).$(AssemblyVersion).nupkg -s https://www.nuget.org/api/v2/package "></Exec>
</Target>
OR
Here’s a version that will ensure releases with a .0 revision number are properly pushed.
<Target Name="PushPackageTarget" AfterTargets="Pack" Condition=" '$(Configuration)' == 'Release'">
< GetAssemblyIdentity AssemblyFiles="$(TargetPath)">
<Output TaskParameter="Assemblies" ItemName="AssemblyVersion" />
</GetAssemblyIdentity>
< PropertyGroup>
< vMajor>$([System.Version]::Parse(%(AssemblyVersion.Version)).Major)</vMajor>
< vMinor>$([System.Version]::Parse(%(AssemblyVersion.Version)).Minor)</vMinor>
< vBuild>$([System.Version]::Parse(%(AssemblyVersion.Version)).Build)</vBuild>
< vRevision>$([System.Version]::Parse(%(AssemblyVersion.Version)).Revision)</vRevision>
</PropertyGroup>
<Message Importance="High" Text="Property Group MajorVersion: $(vMajor).$(vMinor).$(vBuild)" />
<Exec Command="dotnet nuget push $(TargetDir)..\$(TargetName).$(vMajor).$(vMinor).$(vBuild).nupkg -s https://www.nuget.org/api/v2/package "></Exec>
</Target>