Incremento versione progetto (in vb.net)
12-01-2024
Creare una versione in formato [anno.mese.giorno.progressivo]
VB.NET
12-01-2024
Creare una versione in formato [anno.mese.giorno.progressivo]
Imports System.Reflection
Module Module1
Sub Main()
Dim assemblyVersion = Assembly.GetExecutingAssembly().GetName().Version.ToString()
Console.WriteLine($"assemblyVersion: {assemblyVersion}")
Console.WriteLine("Premi un tasto per continuare ...")
Console.ReadLine()
End Sub
End Module
Per modificare il file da Visual Studio:
Da inserire prima del tag "</Project>" nel file "nome_progetto.vbproj"
<Target Name="AssemblyVersion" BeforeTargets="CoreCompile" DependsOnTargets="PrepareForBuild">
<PropertyGroup>
<!-- Costanti -->
<AssemblyInfo><![CDATA[My Project\AssemblyInfo.vb]]></AssemblyInfo>
<AssemblyInfoContent>$([System.IO.File]::ReadAllText($(AssemblyInfo)))</AssemblyInfoContent>
<VersionRegex><![CDATA[((\<|\[)\s*(a|A)ssembly\s*:\s*AssemblyVersion\(\s*"(\d+)\.(\d+)\.(\d+)(\.)(\d+)("\)\s*[\>|\]]))]]></VersionRegex>
<BuildAndRevisionRegex>(\d+\.\d+")</BuildAndRevisionRegex>
<!-- Build/Revision da AssemblyInfo -->
<AssemblyVersion>$([System.Text.RegularExpressions.Regex]::Match('$(AssemblyInfoContent)', '$(VersionRegex)'))</AssemblyVersion>
<BuildAndRevision>$([System.Text.RegularExpressions.Regex]::Match('$(AssemblyVersion)', '$(BuildAndRevisionRegex)'))</BuildAndRevision>
<BuildAndRevision>$(BuildAndRevision.Remove($(BuildAndRevision.LastIndexOf("""")), 1))</BuildAndRevision>
<!-- Genera Build/Revision da AssemblyVersion -->
<Build>$(BuildAndRevision.SubString(0, $(BuildAndRevision.LastIndexOf("."))))</Build>
<Revision>$(BuildAndRevision.SubString($([MSBuild]::Add($(BuildAndRevision.LastIndexOf(".")), 1))))</Revision>
<!-- Incrementa Revision di 1 se == a oggi altrimenti riparti da 1 -->
<Revision Condition ="$([System.DateTime]::Now.Day) == $(Build)">$([MSBuild]::Add($(Revision), 1))</Revision>
<Revision Condition ="$([System.DateTime]::Now.Day) != $(Build)">1</Revision>
<!-- Nuovo elemento AssemblyVersion -->
<AssemblyVersion><![CDATA[<Assembly: AssemblyVersion("$([System.DateTime]::Now.ToString("yyyy.M.d.$(Revision)"))")>]]></AssemblyVersion>
</PropertyGroup>
<!-- Scrivo elemento AssemblyVersion in AssemblyInfo.vb -->
<WriteLinesToFile File="$(AssemblyInfo)" Lines="$([System.Text.RegularExpressions.Regex]::Replace($(AssemblyInfoContent), $(VersionRegex), $(AssemblyVersion)))" Overwrite="true" />
</Target>
Si puĆ² lasciare <Deterministic>true</Deterministic> sempre in .vbproj nel <PropertyGroup> In AssemblyInfo.vb lasciare gli assembly decommentati
<Assembly: AssemblyVersion("2024.1.12.5")>
<Assembly: AssemblyFileVersion("1.0.0.0")>