Link to home
Start Free TrialLog in
Avatar of kpcapel
kpcapel

asked on

Version information in a vb.net dll or exe

Does anyone now how to add something to the version info block in a .net application?  The default stuff is defined in the generated AssemblyInfo.vb file like this <Assembly: AssemblyTitle("some title")>.  I have a custom piece of version info that I always add to anything built in VC++ 6.0 where it is easy to do so.  I suppose I've got to add it to this AssemblyInfo.vb file somehow.  

Hopefully this is relatively simple, but I just don't have any more time to figure it out.  Thanks.
Avatar of NetPointer
NetPointer

Didnt get your question exactly, but here is the things which I know..
Following Line defines the version in assemblyinfo.vb file.

<Assembly: AssemblyVersion("0.1.1")>

AssemblyVersion      Effective Value
not present      0.0.0.0
1            1.0.0.0
1.2            1.2.0.0
1.2.3            1.2.3.0
1.2.3.4            1.2.3.4
1.2.*            1.2.D.S
1.2.3.*            1.2.3.S

where:
D = number of days since February 1, 2000
S = number of seconds since midnight / 2

HTH
NetPointer
Avatar of kpcapel

ASKER

Let me see if I can clarify my question.  Let's say that I have a dll.  If you right click on the dll in Windows Explorer, then click properties, and then click the version tab, you will see the version information.  By default a dll built with .net will display the following...

Assembly Version
Comments
Company
File Version
Internal Name
Language
Legal Trademarks
Original File name
Product Name
Product Version

What I want to do is add a custom item to this.  As I said, its quite easy with VC++ 6.0, you just edit resource file and add it.  Trying to do it with vb.net is not nearly so obvious.
I dont know about this... but I guess this should be done with the metadata...and thus reflection...

proper direction may be usage of custom attributes.

HTH
NetPointer
Avatar of kpcapel

ASKER

yes - .net SDK says that it is - and this is what I've been playing with but no success.
seems fun to do this.. I m also working on it. will get back to you if succeed...
I have managed to add the attrib in manifest...but still it is not showing up in right click...

I have created this class and now u can place that attrib in your assembly...and also it is there in manifest

<AttributeUsage(AttributeTargets.Assembly)> Public NotInheritable Class myassmattrib
    Inherits System.Attribute
    Public _info As String
    Public Sub New(ByVal info As String)
        _info = info
    End Sub
End Class

if u go any further then write me back...

Regards,
NetPointer
It can be helpful to me in  going to right direction, if you can tell me how u had done that in VC...


Regards,
NetPointer
Avatar of kpcapel

ASKER

In VC++ it is quite easy.  To the project resources you first add a version info block.  That gives you the default stuff.  The resource tab in the VC++ IDE provides a user friendly way to change the various fields in the version info.  If you'd like to add a custom one, you manually edit the underlying .rc file outside of the IDE.  The .rc file is a generated file, but it can be modified.  Below is an excerpt from one of my resource files.  Notice the VALUE "BuildDate" field.  That was manually added and is viewable from Explorer in the compiled DLL.  Names have been changed to protect the guilty. :)

VS_VERSION_INFO VERSIONINFO
 FILEVERSION 4,3,0,2
 PRODUCTVERSION 4,3,0,0
 FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
 FILEFLAGS 0x1L
#else
 FILEFLAGS 0x0L
#endif
 FILEOS 0x40004L
 FILETYPE 0x2L
 FILESUBTYPE 0x0L
BEGIN
    BLOCK "StringFileInfo"
    BEGIN
        BLOCK "040904b0"
        BEGIN
            VALUE "BuildDate", "10/14/2003\0"
            VALUE "Comments", "\0"
            VALUE "CompanyName", "My company\0"
            VALUE "FileDescription", "My DLL\0"
            VALUE "FileVersion", "4.3.0.2\0"
            VALUE "InternalName", "CodeName X\0"
            VALUE "LegalCopyright", "Copyright© My Company 2003\0"
            VALUE "LegalTrademarks", "My Company®, My Product®\0"
            VALUE "OriginalFilename", "mydll.dll\0"
            VALUE "PrivateBuild", "\0"
            VALUE "ProductName", "My Product®\0"
            VALUE "ProductVersion", "4.3.0.0\0"
            VALUE "SpecialBuild", "\0"
        END
    END
    BLOCK "VarFileInfo"
    BEGIN
        VALUE "Translation", 0x409, 1200
    END
END
Avatar of kpcapel

ASKER

Anybody got a line on this?  I've increased the points.
Hi...

sorry to be late. it was week end.

I have come up with few things...

It seems this is not a possible.

I will explain why I came to this point. For this we need to understand the PE Executable format generated by .NET Compilers.

Its like this..

Section:                PE/COFF headers

Section:               CLR Header


Section:               CLR Data (Metadata + IL)


Section:               Native Image Section (.data, .rdata, .rsrc, .text)

I have used ildasm and dumpbin to check the files generated by .net...now using reflections and custom atributes, you can easily play with CLR Header and CLR Data...but u do not have access to NIS and PE Headers section.

this means, compilers uses the #pragma to generate this custom sections in PE files, and they reserve their rights to modify main sections of the PE files..they dont give us that access...

unfortunately, the properties we are trying to access, are stored in native image section.and we dont have access to it. (you can verify by using ildasm, and opening exe directly into notepad. dumpbin will also help u.

now in VC++ you can do this as VC++ compiler allows u to play with PE file format...

If still you want to do this, then you can do this with the unsafe code in managed extension for c++.. but not in any of the managed code.

to check the arguments I have made, follow this step.

Create a console application: helloworld.exe
which writes helloworld on screen.
go to asssembly info and write a string in AssemblyTitle which u can later  seach.

use dumpbin.exe for this exe generated file. find the AssemblyTitle u have given in the output of dumpbin.

u can see that versioninfo block is in  RAW DATA #3 under SECTION HEADER #3. now all we can play with is SECTION HEADER #1.

I hope this is clear enough. I would love to continue this thread. so will wait for your inputs. or you can do this by closing this thread and we will continue on our personal mail address...what ever u prefer.


Regards,
NetPointer
Avatar of kpcapel

ASKER

Interesting.  Let me digest what you've found for a bit.
Avatar of kpcapel

ASKER

NetPointer,

For the most part, I can confirm what you've said.  However, I'm not ready to believe that this cannot be done in .Net, especially because its so easy in VS6.

I opened a support case with Microsoft on this, and I'm working with the .Net developers.  I didn't want to pay actual money, but I need this.  When I'm through working with them (probably a few days), I'll post all the information here for everyone.
Avatar of kpcapel

ASKER

Here is the solution with help from Microsoft.  This is not a particularly pretty process, but it works.  After figuring out all the necessary options for my project in the command-line compiler, I got the result I was looking for.

1. Build the DLL in VS .NET (this is to get the initial resources created from the assembly info).
2. Open the DLL in VS .NET.
3. go to File -> Save <dll> As.
4. In the Save As dialog change the Save As type to a Resource Script (.rc).
5. Edit the .rc file to add your customer VALUE.
6. Use rc.exe (with /r switch to generate .res file) to compile the .rc file into a .res file. (Use .net Command Prompt)

7. Use vbc.exe (command-line) with the /win32resource option to embed the .res file ( or csc with the /win32res option )


oh ok.. I was going on wrong track then... I was working on AL.exe... :-(

any way..good to know this.

thanks for the info too.

Regards,
NetPointer
ASKER CERTIFIED SOLUTION
Avatar of SpazMODic
SpazMODic

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial