Automatic NugetPackage upload to Nuget feed

戏子无情 提交于 2019-12-08 05:57:10

问题


Is it possible to automatically upload a Nuget package to a feed when building a project using Visual Studio 2017 and .net core?

I can check the option to automatically generate the package, but I don't know how to automate the publish process.

Thanks!


回答1:


Is it possible to automatically upload a Nuget package to a feed when building a project using Visual Studio 2017 and .net core?

The answer is yes. Since NuGet Command Line Interface (CLI) provides the full extent of NuGet functionality to install, create, publish, and manage packages.

https://docs.microsoft.com/en-us/nuget/tools/nuget-exe-cli-reference#push

We could add a target to execute the publish command line after Visual Studio generate package. In addition, when you check the option to automatically generate the package, you can notice that the target which generate the package is "GenerateNuspec" (MSBuild project build output verbosity->Detailed). So we could a target after the target "GenerateNuspec"

<Target Name="PushNuGetPackage" AfterTargets="GenerateNuspec">

Right click project->Select Edit projectname.csproj->Add below scripts:

  <Target Name="PushNuGetPackage" AfterTargets="GenerateNuspec">
    <Message Text="Push NuGet Package to NuGet Feed" Importance="high"></Message>
    <Exec Command="D:\nuget.exe push $(ProjectDir)bin\Debug\AutoPushNuGetPackageTest.1.0.0.nupkg -Source D:\LocalServer"></Exec>
  </Target>

Note: The exec command should be:

<Exec Command="PathOfYourNuGet\nuget.exe push PathOfYourPackage\PackageName.nupkg -Source NuGetFeedPath"></Exec>

With this target, Visual Studio will automatically upload a Nuget package to a feed when building a project using Visual Studio:



来源:https://stackoverflow.com/questions/46310745/automatic-nugetpackage-upload-to-nuget-feed

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