I am drowning in nuget repostories (20+ nugets) and I can build and pack a nuget via Visual Studio 2017. Thats pretty and fine.

What I am missing is the last mile pushing the nuget to the server.

To do this I have to go to the projects \src\bin\Release\netcoreapp2.2\publish directory, open a command line and type in the f.. command to push the nuget to the server.

That doesn't feel like the 3rd century.

Anyway to automate this?

I understand I have a special use case (during my current development step) which will be obsolete later. Currently I a converting existing codes to nugets and I don't want to increment version numbers during the multiple builds unitl the first version is ready and until the first version isn't ready we don't use a CI / build server and I have to build the nugets locally.

This involves the problem that building a new nuget package (with new code) but the same version leaves the old code (under the same version number) in the local nuget caches. Therefor I have to clean the nuget caches (and reload them which one should do only if a nuget caching server is used or a high network traffic will be the result).

The best way I figured out so far was utilizing MSBuild targets.

I came so far:

  <Target Name="DeployReleaseNuget" AfterTargets="Pack" Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
    <Exec Command="nuget locals all -clear"></Exec>
    <Exec Command="nuget push -Source http://debug.our-nuget.server/v3/index.json &quot;$(OutputPath)publish\$(PackageId).$(PackageVersion).nupkg&quot;" />

  <Target Name="DeployReleaseNuget" AfterTargets="Pack" Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
    <Exec Command="nuget locals all -clear"></Exec>
    <Exec Command="nuget push -Source http://release.our-nuget-server/v3/index.json &quot;$(OutputPath)publish\$(PackageId).$(PackageVersion).nupkg&quot;" />

This seems to work so far, I just can't figure out how to tie the target to a specific publish profile (which I named 'TestProfile'). It seems there is no variable for the profile name? So far each build (even on the build server just using the command line to build triggers the upload, which is unintended.

0 Answers