Publish NuGet artifact to account feed only on tag push

leonard.thieu's Avatar

leonard.thieu

10 Aug, 2017 09:03 PM

I'm trying to publish a NuGet artifact only on tag push. I've tried

deploy:
  - provider: NuGet
    server: https://ci.appveyor.com/nuget/leonard-thieu-h8hvbe0oe9o1/api/v2/package
    api_key:
      secure: <api_key>
    artifact: /$(PROJECT).*\.nupkg/
    on:
      appveyor_repo_tag: true

but this doesn't seem to work as it requires the NuGet package to be pushed as an artifact and the act of pushing the artifact also causes it to be published. It happens even if I change the artifact's type to File or set publish_nuget to false. Based on Publishing nuget artifact only on git tags, it looks like I have to write my own script to do this. I wrote the following script (note the tag check is temporarily inverted for testing)

deploy_script:
  - ps: |
      $appveyor_repo_tag = $env:APPVEYOR_REPO_TAG

      if ($appveyor_repo_tag -eq "false") {
        $configuration = $env:CONFIGURATION
        $platform = $env:PLATFORM
        $appveyor_build_folder = $env:APPVEYOR_BUILD_FOLDER
        $project = $env:PROJECT

        if ($configuration -eq "") {
          $configuration = "Debug";
        }
        switch ($platform) {
          "x86" { break }
          "x64" { break }
          default { $platform = "AnyCPU" }
        }

        nuget pack "$appveyor_build_folder\$project\$project.csproj" -Properties "Configuration=$configuration;Platform=$platform"

        [xml]$nuspec = Get-Content -Path "$appveyor_build_folder\$project\$project.nuspec"
        $version = $nuspec.package.metadata.version

        $api_key = $env:NUGET_API_KEY

        nuget push "$appveyor_build_folder\$project.$version.nupkg" -Source "https://ci.appveyor.com/nuget/leonard-thieu-h8hvbe0oe9o1/api/v2/package" -ApiKey "$api_key" -NonInteractive
      } else {
        Write-Host ""NuGet" deployment has been skipped as environment variable has not matched ("appveyor_repo_tag" is "$appveyor_repo_tag", should be "true")"
      }

which reports success (full build log)

Pushing toofz.NecroDancer.Leaderboards.3.0.7.nupkg to 'https://ci.appveyor.com/nuget/leonard-thieu-h8hvbe0oe9o1/api/v2/package'...
  PUT https://ci.appveyor.com/nuget/leonard-thieu-h8hvbe0oe9o1/api/v2/package/
  Created https://ci.appveyor.com/nuget/leonard-thieu-h8hvbe0oe9o1/api/v2/package/ 806ms
Your package was pushed.

but the new package doesn't show up when I check in Visual Studio.

  1. Support Staff 1 Posted by Ilya Finkelshte... on 10 Aug, 2017 10:57 PM

    Ilya Finkelshteyn's Avatar

    You do not have to do nuget push command, you can simple publish nuget artifact and AppVeyor will publish it to project and account nuget feeds.
    Regarding visibility in VS, please try Include prerelease checkbox.

  2. 2 Posted by leonard.thieu on 10 Aug, 2017 11:22 PM

    leonard.thieu's Avatar

    Thanks. Using Push-AppveyorArtifact in place of nuget push fixes the issue. I did not have to use the Include prerelease checkbox.

  3. leonard.thieu closed this discussion on 10 Aug, 2017 11:22 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac

Recent Discussions

18 Oct, 2017 08:54 AM
18 Oct, 2017 08:21 AM
18 Oct, 2017 07:42 AM
17 Oct, 2017 07:36 PM
17 Oct, 2017 05:39 PM

 

17 Oct, 2017 04:29 PM
17 Oct, 2017 07:49 AM
16 Oct, 2017 11:38 PM
16 Oct, 2017 10:01 PM
16 Oct, 2017 08:25 AM
16 Oct, 2017 07:58 AM