tag:help.appveyor.com,2012-11-13:/discussions/questions/2539-nuget-releaseprerelease-deployment-based-on-tagAppVeyor: Discussion 2018-10-19T08:17:58Ztag:help.appveyor.com,2012-11-13:Comment/404714402016-08-04T23:24:02Z2016-08-04T23:24:02ZNuGet release/prerelease deployment based on tag<div><p>Hello,</p>
<p>Thank you for good words!</p>
<p>According to <a href="https://docs.nuget.org/create/versioning">https://docs.nuget.org/create/versioning</a>,
per my understanding, prerelease version is version appended by
some string like “-alpha”. In your <a href="https://github.com/another-guy/Mirror/blob/master/Build.ps1">https://github.com/another-guy/Mirror/blob/master/Build.ps1</a>,
you generate revision and unconditionally add it with
--version-suffix=$revision statement in line 30. Per <a href="https://docs.microsoft.com/en-us/dotnet/articles/core/tools/dotnet-pack">
https://docs.microsoft.com/en-us/dotnet/articles/core/tools/dotnet-...</a>
--version-suffix “updates the star in -* package version
suffix with a specified string”. Therefore I believe that if
you add some --version-suffix it will be pre-release.</p>
<p>Try to do the following:<br>
Parse APPVEYOR_REPO_TAG_NAME environment variable</p>
<ul>
<li>
<pre>
<code> If tags that look like "1.0.1": don’t add --version-suffix or not at all.</code>
</pre></li>
<li>
<pre>
<code> If tag looks like “1.0.1-b00123”: add --version-suffix=b00123</code>
</pre></li>
</ul>
<p>What about deployment strategy, we discuss it case by case, and
do not have universal solution. Your approach looks good :)</p>
<p>--ilya.</p></div>Ilya Finkelshteyntag:help.appveyor.com,2012-11-13:Comment/404714402016-08-04T23:46:53Z2016-08-04T23:46:53ZNuGet release/prerelease deployment based on tag<div><p>Thank you, Ilya.</p>
<p>Your suggestion regarding the --version-suffix key looks
reasonable. I'll give it a shot and see how it goes.</p></div>soloydenkotag:help.appveyor.com,2012-11-13:Comment/404714402016-08-05T06:17:10Z2016-08-05T06:18:17ZNuGet release/prerelease deployment based on tag<div><p>Good news! As per your recommendation I have modified my
Build.ps1 script and it is now capable of building both prerelease
as well as release versions of the package depending on the commit
tag's value.</p>
<p>Unfortunately, I had to add an additional (pretty fragile) code
that checks "compatibility" of tag version against the version
specified in project.json. This is needed to prevent accidental
releases without prior project.json metadata update.</p>
<pre>
<code>$tagOfHead = iex 'git tag -l --contains HEAD'
$prefixExpected = $tagOfHead + "-"
$projectJson = Get-Content '.\Mirror\project.json' | Out-String | ConvertFrom-Json | select -ExpandProperty version #| Select-Object -Property version
if ([string]::IsNullOrEmpty($tagOfHead)) {
$revision = @{ $true = $env:APPVEYOR_BUILD_NUMBER; $false = 1 }[$env:APPVEYOR_BUILD_NUMBER -ne $NULL];
$revision = "b{0:D5}" -f [convert]::ToInt32($revision, 10)
exec { & dotnet pack .\Mirror -c Release -o .\artifacts --version-suffix=$revision }
} elseif ($projectJson.StartsWith($prefixExpected,"CurrentCultureIgnoreCase")) {
exec { & dotnet pack .\Mirror -c Release -o .\artifacts }
} else {
throw ("Target commit is marked with tag " + $tagOfHead + " which is not compatible with project version retrieved from metadata: " + $projectJson)
}</code>
</pre>
<p>(See <a href="https://github.com/another-guy/Mirror/blob/master/Build.ps1#L29">https://github.com/another-guy/Mirror/blob/master/Build.ps1#L29</a>
for details)</p>
<p>@Ilya, I know this goes beyond support staff "duties" but if you
have spare minute and desire to help further, could you review my
approach and suggest improvements? I am very new to powershell and
CI and automation tools in .NET world.</p></div>soloydenkotag:help.appveyor.com,2012-11-13:Comment/404714402016-08-05T19:20:20Z2016-08-05T19:20:20ZNuGet release/prerelease deployment based on tag<div><p>Hi,</p>
<p>I think that script is good, just minor notes</p>
<ol>
<li>
<pre>
<code> Are you sure you need “-*” in project.json version? Maybe you can just set it to 1.0.2 instead of 1.0.2-* and check if it is equal to $tagOfHead (without introducing $prefixExpected variable at all)?</code>
</pre></li>
<li>
<pre>
<code> NIT: rename $projectJson to $projectJsonVersion ☺</code>
</pre></li>
</ol>
<p>Thank you,<br>
Ilya.</p></div>Ilya Finkelshteyntag:help.appveyor.com,2012-11-13:Comment/404714402016-08-05T23:55:11Z2016-08-05T23:55:11ZNuGet release/prerelease deployment based on tag<div><ol>
<li>
<p>I'd rather leave the "*" in some form. It can be either used as
a build number (as it is now) or be an exact match of the tag
applied to the commit being build. Not sure which one is better for
me. The "*" lets me avoid manual PATCH version (as in SemVer)
update. I only need to intervene when MAJOR or MINOR versions
should be changed.</p>
</li>
<li>
<p>Nice catch.</p>
</li>
</ol>
<p>Thank you for your time again Ilya!</p></div>soloydenko