tag:help.appveyor.com,2012-11-13:/discussions/questions/1180-date-based-versioningAppVeyor: Discussion 2018-08-25T01:55:37Ztag:help.appveyor.com,2012-11-13:Comment/365089552015-04-07T17:37:47Z2015-04-07T17:37:47ZDate based versioning<div><p>Hi Jonas,</p>
<p>You can use <a href="http://www.appveyor.com/docs/build-worker-api#update-build-details">
Update build API</a> in <code>init</code> section of your build.
Something like:</p>
<pre>
<code>init:
- ps: Update-AppveyorBuild -Version "1.$(Get-Date -format yyyy.M).$env:appveyor_build_number"</code>
</pre></div>Feodor Fitsnertag:help.appveyor.com,2012-11-13:Comment/365089552015-04-07T17:44:02Z2015-05-07T06:16:01ZDate based versioning<div><p>Thanks!</p>
<p>Now, as a clomplete newbie to both AppVeyor and yaml - is that
something I can write in the <strong>Settings / Build Version
Format</strong> field, or does it have to be done with some yaml
magic?</p></div>jonas.rapptag:help.appveyor.com,2012-11-13:Comment/365089552015-04-07T17:46:21Z2015-04-07T17:46:21ZDate based versioning<div><p>You can't use date parts in version format.</p>
<p>There is no yaml magic - it's PowerShell magic :) and you can
put the same command to "Init script" field on UI (and choosing
<code>PS</code> as script type):</p>
<pre>
<code>Update-AppveyorBuild -Version "1.$(Get-Date -format yyyy.M).$env:appveyor_build_number"</code>
</pre></div>Feodor Fitsnertag:help.appveyor.com,2012-11-13:Comment/365089552015-04-07T17:52:22Z2015-05-07T06:16:01ZDate based versioning<div><p>Ah - I think I got it :)<br>
And then I leave the <strong>Build Version Format</strong> field
blank, or is it overwritten anyway by the init script?</p></div>jonas.rapptag:help.appveyor.com,2012-11-13:Comment/365089552015-04-07T17:58:19Z2015-04-07T17:58:19ZDate based versioning<div><p>Yes, it will be overwritten, but do not leave it blank - put
just <code>{build}</code> there.</p></div>Feodor Fitsnertag:help.appveyor.com,2012-11-13:Comment/365089552015-04-15T10:44:03Z2015-05-07T06:16:01ZDate based versioning<div><p>Hi again</p>
<p>I have probably just missed something really stupid, but when I
was going to adopt this to my next project, I get the following
error during build:</p>
<pre>
<code>Build started
SET /A "year=%Date:~10,4%"
SET /A "month=%Date:~4,2%"
Fetching repository commit (862f47a)...OK
Total: 2.1 MB in 66 files
Patching AssemblyInfo
Patching VersionInfo.cs...Wrong version format for assembly patching: 1.2015.4.$2</code>
</pre>
<p>I just don't get it...</p></div>jonas.rapptag:help.appveyor.com,2012-11-13:Comment/365089552015-04-15T10:59:51Z2015-05-07T06:16:01ZDate based versioning<div><p>Another thing noted:<br>
The build version shown in the build history is<br></p>
<pre>
<code>3.master
2.master
1.master</code>
</pre>
In the previous project version is good, e.g. 1.2015.4.34 etc.<br>
But the settings are identical in the two projects.
<p>yaml from the new project:<br></p>
<pre>
<code>version: .{build}
branches:
only:
- master
configuration: Release
init:
- ps: Update-AppveyorBuild -Version "1.$(Get-Date -format yyyy.M).$env:appveyor_build_number"
assembly_info:
patch: true
file: '**\VersionInfo.*'
assembly_version: '{version}'
assembly_file_version: '{version}'
assembly_informational_version: '{version}'
build:
verbosity: minimal
after_build:
- 7z a Cinteros.XrmToolBox.Plugins_%APPVEYOR_BUILD_VERSION%.zip %APPVEYOR_BUILD_FOLDER%\Output\%CONFIGURATION%\Cinteros.Xrm.*.dll
- appveyor PushArtifact Cinteros.XrmToolBox.Plugins_%APPVEYOR_BUILD_VERSION%.zip
deploy:
- provider: Environment
name: GitHubCintXTB</code>
</pre></div>jonas.rapptag:help.appveyor.com,2012-11-13:Comment/365089552015-04-15T18:08:55Z2015-04-15T18:08:55ZDate based versioning<div><p>Obviously, you can't put anything into
<code>AssemblyVersion</code> and <code>AssemblyFileVersion</code>
attributes. They only accept the value in the form
<code>a.b.c.d</code>. Use just something like
<code>1.{build}</code> there.</p></div>Feodor Fitsnertag:help.appveyor.com,2012-11-13:Comment/365089552015-04-15T18:58:02Z2015-05-07T06:16:01ZDate based versioning<div><p>Obviously, no that is not a proper format.</p>
<p>What I meant was that using the same settings, I don't
understand why the two projects behave differently.<br>
When the first project generates a version like
<code>1.2015.4.37</code> and the second, using the same settings,
generates a version like <code>1.2015.4.$5</code>.<br>
And why the first projects build is named <code>1.2015.4.37</code>
when the second project is named <code>5.master.</code></p>
<p>I was just looking for clues to why they behave differently
using the same settings, if You might have any idea.</p></div>jonas.rapptag:help.appveyor.com,2012-11-13:Comment/365089552015-04-15T19:00:33Z2015-04-15T19:00:33ZDate based versioning<div><p>Ah, I see what you mean :) Assembly patching can automatically
strip the suffix in versions of format
<code>a.b.c-suffix</code></p></div>Feodor Fitsnertag:help.appveyor.com,2012-11-13:Comment/365089552015-04-15T19:07:01Z2015-05-07T06:16:01ZDate based versioning<div><p>Great :)</p>
<p>But is there a way to explain why this does not work?<br>
Because now I can't get it to work.</p>
<p>Working yaml:<br></p>
<pre>
<code>version: '{build}'
branches:
only:
- master
configuration: Release
init:
- ps: Update-AppveyorBuild -Version "1.$(Get-Date -format yyyy.M).$env:appveyor_build_number"
assembly_info:
patch: true
file: '**\AssemblyInfo.*'
assembly_version: '{version}'
assembly_file_version: '{version}'
assembly_informational_version: '{version}'
build:
verbosity: minimal
after_build:
- 7z a FetchXMLBuilder_%APPVEYOR_BUILD_VERSION%.zip %APPVEYOR_BUILD_FOLDER%\FetchXMLBuilder\bin\%CONFIGURATION%\Cinteros.Xrm.*.dll
- appveyor PushArtifact FetchXMLBuilder_%APPVEYOR_BUILD_VERSION%.zip
deploy:
- provider: Environment
name: GitHubFXB</code>
</pre>
Not working yaml:<br>
<pre>
<code>version: '{build}'
branches:
only:
- master
configuration: Release
init:
- ps: Update-AppveyorBuild -Version "1.$(Get-Date -format yyyy.M).$env:appveyor_build_number"
assembly_info:
patch: true
file: '**\VersionInfo.*'
assembly_version: '{version}'
assembly_file_version: '{version}'
assembly_informational_version: '{version}'
build:
verbosity: minimal
after_build:
- 7z a Cinteros.XrmToolBox.Plugins_%APPVEYOR_BUILD_VERSION%.zip %APPVEYOR_BUILD_FOLDER%\Output\%CONFIGURATION%\Cinteros.Xrm.*.dll
- appveyor PushArtifact Cinteros.XrmToolBox.Plugins_%APPVEYOR_BUILD_VERSION%.zip
deploy:
- provider: Environment
name: GitHubCintXTB</code>
</pre></div>jonas.rapptag:help.appveyor.com,2012-11-13:Comment/365089552015-04-15T19:13:11Z2015-04-15T19:13:11ZDate based versioning<div><p>Don't see any difference in terms of setting version number.</p>
<p>Try outputting it into build console with:</p>
<pre>
<code>init:
- ps: "1.$(Get-Date -format yyyy.M).$env:appveyor_build_number"</code>
</pre></div>Feodor Fitsner