Automatic NugetPackage upload to Nuget feed

2019-06-05 06:19发布

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条回答
别忘想泡老子
2楼-- · 2019-06-05 07:02

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:

enter image description here

查看更多
登录 后发表回答