问题描述
使用Visual Studio 2017和.net core构建项目时,是否可以将Nuget包自动上传到feed?
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.
谢谢!
推荐答案
答案是肯定的.由于NuGet命令行界面(CLI)提供了完整的NuGet功能,可以安装,创建,发布和管理软件包.
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
我们可以添加一个目标,以便在Visual Studio生成包后执行发布命令行.此外,当您选中自动生成程序包的选项时,您会注意到生成程序包的目标是"GenerateNuspec
"(MSBuild项目生成输出详细程度->详细).这样我们就可以在目标"GenerateNuspec
"
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">
右键单击项目->选择编辑projectname.csproj
->添加以下脚本:
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>
注意:exec命令应为:
Note: The exec command should be:
<Exec Command="PathOfYourNuGet\nuget.exe push PathOfYourPackage\PackageName.nupkg -Source NuGetFeedPath"></Exec>
有了这个目标,Visual Studio将在使用Visual Studio构建项目时自动将Nuget包上传到feed:
With this target, Visual Studio will automatically upload a Nuget package to a feed when building a project using Visual Studio:
这篇关于自动将NugetPackage上传到Nuget提要的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!