- Increment Package version - Something similar to "npm version patch"
Before answering this question, we need to know some info about the AssemblyVersion
, AssemblyInformationalVersion
and NuGet version, please check this thread for some details. Then you will know that:
Nuget doesn’t use either AssemblyVersion
or AssemblyFileVersion
in the AssemblyInfo.cs
file. It uses a third versioning attribute: AssemblyInformationalVersion
.
Nuget actually applys whatever is in that string as the package version. So, to increment package version, we need to manually add following code in the AssemblyInfo.cs
:
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("2.0.0")]
So, when we need to release a new version package, we just need to update the value of AssemblyInformationalVersion
in the AssemblyInfo.cs
file.
- Build package
The answer for this question depends on the style of your project, the old project style or the new project style(VS2017-SDK).
Source Old csproj to new csproj: Visual Studio 2017 upgrade guide
When you're in the old style project:
You can just pack the nuget package automatically by a post-build event:
$(PathOfYourNuGet)\nuget.exe pack "$(ProjectPath)"
With this build event, MSBuild will create the nuget package automatically when you build the project.
When you in the New style project:
In the new style project, packagin nuget package becomes very easy. Just check the checkbox Generate NuGet packafe on build
on package tab of the project properties:

Note: When you are in the new style project, you can increment package version in the Package version on the package tab.
- Push just created package to the NuGet repository
Just as you found, after publishing the nuget package automatically, you can add a custom target to push it:
<Target Name="PushNuGetPackage" AfterTargets="GenerateNuspec">
<Message Text="Push NuGet Package to NuGet Feed" Importance="high"></Message>
<Exec Command="$(PathOfYourNuGet)\nuget.exe push $(TargetDir)\xxx.1.0.0.nupkg -Source NuGetrepository"></Exec>
</Target>
Source Automatic NugetPackage upload to Nuget feed
Note: You can not push the nuget package with same name and same version to the nuget.org.