Automatically publish a NuGet package built with VS2017

风格不统一 提交于 2019-12-03 03:22:25

You can automate a publish to nuget by adding the below line to your libraries csproj directly. You will need to either set an environment variable to the location of your nuget.exe, add the location to your system's PATH, or hard enter it into the Command parameter.

Personally, I prefer to download the latest version of nuget.exe and place it into the user's %userprofile%\.nuget folder. This is where nuget stores the local cache of packages, so it should be already created.

Example of publishing to a remote repository.

<Target Name="PostPackNugetDeploy" AfterTargets="Pack" Condition="'$(Configuration)' == 'Release'">
  <Exec Command="="%userprofile%\.nuget\nuget.exe push &quot;$(OutputPath)$(PackageId).$(PackageVersion).nupkg&quot; -Source &quot;$(NuGetSourceRelease)&quot; -Verbosity Detailed" />
</Target>

Example of publishing to a local repository.

<Target Name="PostPackNugetDeploy" AfterTargets="Pack" Condition="'$(Configuration)' == 'Release'">
 <Exec Command="%userprofile%\.nuget\nuget.exe add &quot;$(OutputPath)$(PackageId).$(PackageVersion).nupkg&quot; -source \\Server\Packages" />
</Target>

You can find the docs on the MSBuild targets for nuget here https://docs.microsoft.com/en-us/nuget/reference/msbuild-targets

Update

I have wrapped this into a nuget package that can be referenced within your project. It takes care of all this, all you have to do is add a property to your project.

You can fine the code and full guide here.
https://github.com/SimplerSoftware/SS.NuGet.Publish

This feature has been requested here: Enable push from VS.

NuGet publish is generally handled using build/deployment automation software like TFS, VSTS, Jenkins, etc.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!