That's what worked for me:
<PropertyGroup>
<VersionMajor Condition="'$(VersionMajor)' == ''">0</VersionMajor>
<VersionMinor Condition="'$(VersionMinor)' == ''">0</VersionMinor>
<VersionPatch Condition="'$(VersionPatch)' == ''">$([System.DateTime]::UtcNow.Subtract($([System.DateTime]::new(2001,1,1))).TotalDays.ToString("0"))</VersionPatch>
<VersionRevision Condition="'$(VersionRevision)' == ''">$([System.DateTime]::UtcNow.TimeOfDay.TotalMinutes.ToString("0"))</VersionRevision>
<Version>$(VersionMajor).$(VersionMinor).$(VersionPatch).$(VersionRevision)</Version>
</PropertyGroup>
Here I manually set VersionMajor and VersionMinor. Then I have autoincremented values for Patch and revision.
- Patch : number of days since 2001/01/01 (first day of century XXI).
- Revision : total minutes of the day
That's good enought untill June 2180 (Remember máx versión number is 65534).
Extra tip:
I put all this lines into a Version.Build.props file into Properties folder. Then I import it from csproj file with this tag:
<Import Project="$([MSBuild]::GetPathOfFileAbove('Version.Build.props', '$(MSBuildThisFileDirectory)/Properties/'))" />
This way, I can manually set proyect versions manually in my csproj file, left them in auto or a mix of them by just setting VersionMajor and VersionMinor which is what I actually do.
[System.DateTime]::UtcNow.ToString(mmff)
. – Shiah