Automating Nuget Package Push With .NetCore RC2

有些话、适合烂在心里 提交于 2019-12-03 20:42:46

RC2 replaced prebuild and postbuild with precompile and postcompile.

You can use the postcompile to automatically generate the nupkg and to push the package to a nuget server using

"scripts": {
    "postcompile": [
  "dotnet pack --no-build",
  "\"%project:Directory%\\..\\..\\nuget.exe\" push \"%project:Directory%\\bin\\%compile:Configuration%\\%project:Name%.%project:Version%.nupkg\" -source nugetserver -ApiKey key"
]
  }

This will automatically call the dotnet pack using the project.json file that exists in the project directory. Then it will push the nuget package to the specified nuget server.

Unfortunately there is no variable to specifiy the build configuration therefore in the above path you will have to manually change it when you switch between debug and release configuration.

The above uses %compile:Configuration% to specify the current build configuration.

The answer to the current build configuration comes from How to run scripts based on solution configuration in ASP.NET Core RC2

Visual Studio 2017

In Visual Studio 2017 you can use the dotnet nuget push command by editing the csproj file and using the following command

<Target Name="PushPackage" AfterTargets="Pack">
    <Exec Command="dotnet nuget push &quot;$(MSBuildProjectDirectory)\bin\$(Configuration)\$(AssemblyName).$(Version).nupkg&quot; -s nugetserver -k apikey" />
</Target>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!