I saw some code like this , in a csproj file
$([System.DateTime]::UtcNow.ToString(mmff))
to autoincrement the assembly version:
<VersionSuffix>2.0.0.$([System.DateTime]::UtcNow.ToString(mmff))</VersionSuffix>
<AssemblyVersion Condition=" '$(VersionSuffix)' == '' ">0.0.0.1</AssemblyVersion>
What kind of language/script is that? How do I use it to get the difference between two dates?
I tried to do something like this:
<VersionMajor>2</VersionMajor>
<VersionMinor>1</VersionMinor>
<DaysFromLastRelease>$(([System.DateTime]::UtcNow - new [System.DateTime](2021,1,1))::TotalDays)</DaysFromLastRelease>
but it does not work:)
.csproj
files are basically MSBuild files (XML). The embedded syntax you are referring to is called a Property Function .
It appears that subtraction using the minus ( -
) might not be supported. There is a Subtract()
property function in Property Functions .
Perhaps this could be the base for a solution. I have not tried it!
<Now>$([System.DateTime]::UtcNow.DayOfYear)</Now>
<January>$([System.DateTime]::new(2021,1,1)).DayOfYear</January>
<!-- or... (not sure about the below)
<January>$([System.DateTime]::Parse("1/1/2021").DayOfYear)</January>
-->
<DaysFromLastRelease>$([MSBuild]::Subtract($(Now), $(January)))</DaysFromLastRelease>
Other possibilities
.csproj
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.
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.