1 Attachment(s)
[RESOLVED] Assembly Version Formatting
:wave:
I have a quick question about the Assembly Version Formatting... (referring to lblRev.Text)
I'm putting together an about screen that has the App information like the version, up time, date, etc.
I would like for it to format all of the numbers I include (including zeros before the number).
Here's my code.
Code:
' Add any initialization after the InitializeComponent() call.
Dim dt As Date = File.GetLastWriteTime(Application.ExecutablePath)
lblLastdate.Text &= dt.ToString("MMM d, yyyy h:mm tt")
lblRev.Text &= My.Application.Info.Version.ToString
lblLastBoot.Text &= started.ToString("MMM d, yyyy h:mm:ss tt")
lblCopyRight.Text &= My.Application.Info.Copyright
My Assembly Version Information is 2.2.2023.0309 (Version 2.2: YYYY:MMDD) is how I am naming the version so that I can keep track of things for my personal info.
I've included an image of the settings below.
Attachment 187516
But when it formats it, it removes the zero before the 3 (2.2.2023.309). I know it's not a huge deal, but if I can keep the zero, I'd prefer it. Is there any way to format this so that it keeps the zero or does Visual Studio just remove it?
Thanks for anyone who can help me with this.
Re: Assembly Version Formatting
You can create a function to do this yourself:-
Code:
Private Function FormatVersion(ByVal version As String) As String
Return String.Join(".", From s In version.Split(".").Select(
Function(value, index)
If index = 2 OrElse index = 3 Then Return value.PadLeft(4, "0"c)
Return value
End Function))
End Function
Tested with this:-
Code:
Debug.WriteLine(FormatVersion("1.2.430.20"))
Produces this output:-
Re: Assembly Version Formatting
Here's a slightly more simplified version:-
Code:
Private Function FormatVersion(ByVal version As String) As String
Return String.Join(".", version.Split(".").
Select(Function(value, index) If(index = 2 OrElse index = 3, value.PadLeft(4, "0"c), value)))
End Function
Re: Assembly Version Formatting
The My.Application.Info.Version property is type Version and the Major, Minor, Build and Revision properties of that are type Integer. Numbers don't have leading zeroes, so you have to add them yourself if you want your string representation to contain them, e.g.
vb.net Code:
Dim v = My.Application.Info.Version
Dim versionText = $"{v.Major}.{v.Minor}.{v.Build}.{v.Revision:0000}"
Re: Assembly Version Formatting
Quote:
Originally Posted by
jmcilhinney
The My.Application.Info.Version property is type Version and the Major, Minor, Build and Revision properties of that are type Integer. Numbers don't have leading zeroes, so you have to add them yourself if you want your string representation to contain them, e.g.
vb.net Code:
Dim v = My.Application.Info.Version
Dim versionText = $"{v.Major}.{v.Minor}.{v.Build}.{v.Revision:0000}"
jmcilhinney,
Thanks for the help! So here's my new code and it works perfectly how I wanted it to. I'm going to do some other stuff now hahaha! That was brilliant and I appreciate it very much.
Thanks to everyone else who responded as well. I love this site and everyone who takes the time to reach out and help others in need. Hopefully one day I'll get to the point where I'm helping others as well haha.
Marking this as [Resolved]
Re: Assembly Version Formatting
Quote:
Originally Posted by
Niya
You can create a function to do this yourself:-
Code:
Private Function FormatVersion(ByVal version As String) As String
Return String.Join(".", From s In version.Split(".").Select(
Function(value, index)
If index = 2 OrElse index = 3 Then Return value.PadLeft(4, "0"c)
Return value
End Function))
End Function
Tested with this:-
Code:
Debug.WriteLine(FormatVersion("1.2.430.20"))
Produces this output:-
Not exactly what I was looking for, but thanks for reaching out. I do appreciate it.
Re: Assembly Version Formatting
Quote:
Originally Posted by
Niya
Here's a slightly more simplified version:-
Code:
Private Function FormatVersion(ByVal version As String) As String
Return String.Join(".", version.Split(".").
Select(Function(value, index) If(index = 2 OrElse index = 3, value.PadLeft(4, "0"c), value)))
End Function
Now this may be something more practical, but jmcilhinney's response is exactly what I was looking for.
I am going to give your suggestion on this option a try as I may be able to use it for my other application where I'm doing something a bit different. Thank you so much Niya for always looking out on my posts haha you have helped me in the past a great deal!!! So I'm always looking for your replies for sure! Thanks again.
Re: [RESOLVED] Assembly Version Formatting
jmc's solution is better than mine. Use that instead ;)
Re: [RESOLVED] Assembly Version Formatting
Because we did not have a versioning system and are relatively small I used this
Major - year
Minor - month
Build - day
Revision - a number or 24 hour time