tag:help.appveyor.com,2012-11-13:/discussions/problems/7319-publish-nuget-artifact-to-account-feed-only-on-tag-pushAppVeyor: Discussion 2018-10-19T08:18:27Ztag:help.appveyor.com,2012-11-13:Comment/431873692017-08-10T21:03:14Z2017-08-10T21:04:20ZPublish NuGet artifact to account feed only on tag push<div><p>I'm trying to publish a NuGet artifact only on tag push. I've tried</p>
<pre>
<code>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</code>
</pre>
<p>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 <code>type</code> to <code>File</code> or set <code>publish_nuget</code> to <code>false</code>. Based on <a href="http://help.appveyor.com/discussions/questions/1337-publishing-nuget-artifact-only-on-git-tags">Publishing nuget artifact only on git tags</a>, 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)</p>
<pre>
<code>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")"
}</code>
</pre>
<p>which reports success (<a href="https://ci.appveyor.com/project/leonard-thieu/toofz-necrodancer-leaderboards/build/3.0.2.21">full build log</a>)</p>
<pre>
<code>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.</code>
</pre>
<p>but the new package doesn't show up when I check in Visual Studio.</p></div>leonard.thieutag:help.appveyor.com,2012-11-13:Comment/431873692017-08-10T22:57:37Z2017-08-10T22:57:37ZPublish NuGet artifact to account feed only on tag push<div><p>You do not have to do <code>nuget push</code> command, you can simple <a href="https://www.appveyor.com/docs/packaging-artifacts/#pushing-artifacts-from-scripts">publish nuget artifact</a> and AppVeyor will publish it to project and account nuget feeds.<br>
Regarding visibility in VS, please try <code>Include prerelease</code> checkbox.</p></div>Ilya Finkelshteyntag:help.appveyor.com,2012-11-13:Comment/431873692017-08-10T23:22:15Z2017-08-10T23:22:15ZPublish NuGet artifact to account feed only on tag push<div><p>Thanks. Using <code>Push-AppveyorArtifact</code> in place of <code>nuget push</code> fixes the issue. I did not have to use the <code>Include prerelease</code> checkbox.</p></div>leonard.thieu