How to get version of application

G

Guest

I have an application migrated from 1.1 to 2.0 via VS2005.

Under 1.1 I could do the following to return the version information (as
found in the assemblyinfo.vb file)

GetVersion =
System.Diagnostics.FileVersionInfo.GetVersionInfo(System.Reflection.Assembly.GetExecutingAssembly.Location).FileMajorPart.ToString
+ "." +
System.Diagnostics.FileVersionInfo.GetVersionInfo(System.Reflection.Assembly.GetExecutingAssembly.Location).FileMinorPart.ToString
+ "." +
System.Diagnostics.FileVersionInfo.GetVersionInfo(System.Reflection.Assembly.GetExecutingAssembly.Location).FileBuildPart.ToString


However, under 2.0, first it appears that the assemblyinfo.vb file is
obsolete and there is no way to set or read a version associated with the
project.

Is there a way to still track a version of the application and then output
it on a web page?
 
S

Steven Cheng[MSFT]

Hi Robert,

Welcome to ASPNET newsgroup.
Regarding on the ASP.NET 2.0 project assembly versioning question, here are
some of my understanding:

Yes, the ASP.NET 2.0 project no longer use the precompiled assemblies which
can be build (and specify version info through assemblyInfo.cs) in VS.NET
2003 IDE. The ASP.NET 2.0 web application (project) utilize new dynamic
compilation model, so the project's assembly will be compiled into a
dynamically generated assembly and namespace (just like the dynamic
compiled one under the Temporary ASPNET folder...), so we won't be able to
specify the info, and that's not quite useful as the one in 1.1.

BTW, the asp.net web tools team currently going to provide a new Web
Deployment project which can provide some customzation features for
precompiled website and deploy website, and one of the feature is assigning
version number and controling how the page or App_Code assemblies are
dynamically compiled, here is the beta preview link for this project:

http://msdn.microsoft.com/asp.net/reference/infrastructure/wdp/default.aspx

Also, here is blog article discussing on the background of this project
(from the ASP.NET web tools &platfform team's mgr...)

http://weblogs.asp.net/scottgu/archive/2005/11/06/429723.aspx

Hope helps. Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)





--------------------
| Thread-Topic: How to get version of application
| thread-index: AcXpfCMkjuavsUoBRTm3XfFgorOPaw==
| X-WBNR-Posting-Host: 67.180.214.235
| From: =?Utf-8?B?Um9iZXJ0?= <[email protected]>
| Subject: How to get version of application
| Date: Mon, 14 Nov 2005 16:33:02 -0800
| Lines: 19
| Message-ID: <[email protected]>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="Utf-8"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| Content-Class: urn:content-classes:message
| Importance: normal
| Priority: normal
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250
| Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGXA03.phx.gbl
| Xref: TK2MSFTNGXA02.phx.gbl
microsoft.public.dotnet.framework.aspnet:358119
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| I have an application migrated from 1.1 to 2.0 via VS2005.
|
| Under 1.1 I could do the following to return the version information (as
| found in the assemblyinfo.vb file)
|
| GetVersion =
|
System.Diagnostics.FileVersionInfo.GetVersionInfo(System.Reflection.Assembly
..GetExecutingAssembly.Location).FileMajorPart.ToString
| + "." +
|
System.Diagnostics.FileVersionInfo.GetVersionInfo(System.Reflection.Assembly
..GetExecutingAssembly.Location).FileMinorPart.ToString
| + "." +
|
System.Diagnostics.FileVersionInfo.GetVersionInfo(System.Reflection.Assembly
..GetExecutingAssembly.Location).FileBuildPart.ToString
|
|
| However, under 2.0, first it appears that the assemblyinfo.vb file is
| obsolete and there is no way to set or read a version associated with the
| project.
|
| Is there a way to still track a version of the application and then
output
| it on a web page?
|
 
Joined
Jul 10, 2007
Messages
2
Reaction score
0
solution.....

:cool: In Vs2005 it made things simpler than earlier... u have to replact with this...


Dim FileVer As String
FileVer = My.Application.Info.Version.ToString
 
Joined
Sep 8, 2007
Messages
2
Reaction score
0
Possible Solution

Shamirza, the solution you posted doesn't work under ASP.NET 2.0, it will only work if you are compiling a Windows application. I found a solution that works, although I would like to find a better one if anybody has a suggestion. This solution doesn't require any downloading :p .

Here is the solution I came up with. It works whether the site has been compiled for deployment or not. It requires imports for System.Reflection and System.Text.RegularExpressions.

I dropped this property into a base class that is located in the App_Code directory. There is also an attribute in an AssemblyInfo.vb file in the App_Code directory as follows: <Assembly: AssemblyVersion("1.1.0000.0009")> .

Of course, for this method to work, you need to ensure the assembly version attribute is located in the same DLL that you are calling the property in after the compile. Keep this in mind if you are compiling each page as a seperate DLL.

Code:
    Protected ReadOnly Property SiteVersion() As String
        Get
            'NOTE: version is pulled from the FullName property of the executing assembly.
            'This property contains the full string, so a regular expression is used to parse
            'the version number out of it.  The string is as follows:
            'FullName: "App_Code.imw2-mqw, Version=1.1.0.9, Culture=neutral, PublicKeyToken=null"

            Dim re As New Regex("Version=(?<ver>[^,]+),", RegexOptions.Compiled)
            Dim m As Match = re.Match(Assembly.GetExecutingAssembly.FullName)
            Dim ver As String = "No version found"
            If m.Success Then
                ver = m.Result("${ver}")
            End If
            Return ver
        End Get
    End Property
 
Joined
Aug 3, 2007
Messages
2
Reaction score
0
Simple Method

Thanks for this information.
I found another method..

lblVersion.Text = GetType(clsStatistic).Assembly.GetName.Version.ToString

"clsStatistic" a class in my project App_Code folder. When it compiled, it became App_Code.dll

You can type any of your class...
 
Joined
Sep 8, 2007
Messages
2
Reaction score
0
m1gin said:
Thanks for this information.
I found another method..

lblVersion.Text = GetType(clsStatistic).Assembly.GetName.Version.ToString

"clsStatistic" a class in my project App_Code folder. When it compiled, it became App_Code.dll

You can type any of your class...

Good find! Still it is a tossup whether to use the assembly directly from getting the type or to use reflection as follows:

Code:
System.Reflection.Assembly.GetExecutingAssembly.GetName.Version.ToString

In either case, I am glad to lose the regular expression parsing. I have already replaced the version code in my QA version info page here:

http://www.shuttercontractor.com/version.aspx
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top