What Was I Thinking?

Follies & Foils of .NET Development
posts - 95 , comments - 352 , trackbacks - 0

My Links

News

Archives

Post Categories

Check These Out

Gurus

Thursday, October 26, 2017

.NET Core–Push Nuget Package After Build

You can configure .NET Core to automatically push your nuget package to the package server of your choice by adding a Target to your project file.

1) If your package server requires an api key, you can set it by calling

nuget.exe SetApiKey <YourKey>

2) Add the following target to your csproj file.   This sample is configured to only fire on Release Builds.

<Target Name="PushTarget" AfterTargets="Pack" Condition=" '$(Configuration)' == 'Release'">   
   <Message Importance="High" Text="This is a test After Build Target--&gt;$(TargetPath)" />
   <GetAssemblyIdentity AssemblyFiles="$(TargetPath)">
     <Output TaskParameter="Assemblies" ItemName="AssemblyVersion" />
   </GetAssemblyIdentity>   
   <Exec Command="dotnet nuget push $(TargetDir)..\$(TargetName).$(AssemblyVersion).nupkg -s https://www.nuget.org/api/v2/package "></Exec>
</Target>

OR

Here’s a version that will ensure releases with a .0 revision number are properly pushed.

<Target Name="PushPackageTarget" AfterTargets="Pack" Condition=" '$(Configuration)' == 'Release'">
    < GetAssemblyIdentity AssemblyFiles="$(TargetPath)">
      <Output TaskParameter="Assemblies" ItemName="AssemblyVersion" />
    </GetAssemblyIdentity>
    < PropertyGroup>
      < vMajor>$([System.Version]::Parse(%(AssemblyVersion.Version)).Major)</vMajor>
      < vMinor>$([System.Version]::Parse(%(AssemblyVersion.Version)).Minor)</vMinor>
      < vBuild>$([System.Version]::Parse(%(AssemblyVersion.Version)).Build)</vBuild>
      < vRevision>$([System.Version]::Parse(%(AssemblyVersion.Version)).Revision)</vRevision>
    </PropertyGroup>
    <Message Importance="High" Text="Property Group MajorVersion: $(vMajor).$(vMinor).$(vBuild)" />   
    <Exec Command="dotnet nuget push $(TargetDir)..\$(TargetName).$(vMajor).$(vMinor).$(vBuild).nupkg -s https://www.nuget.org/api/v2/package "></Exec>
  </Target>

Posted On Thursday, October 26, 2017 2:38 PM | Comments (0) | Filed Under [ Visual Studio ]

Powered by: