Thread overview
How add "version.txt" Version File by Command Line or by resources.res using dmd.exe
Dec 08, 2019
Marcone
Dec 08, 2019
mipri
Dec 08, 2019
Marcone
Dec 08, 2019
GoaLitiuM
Dec 10, 2019
rumbu
Dec 10, 2019
ShadoLight
Dec 10, 2019
Marcone
Dec 10, 2019
ShadoLight
Dec 10, 2019
Marcone
Dec 10, 2019
Marcone
December 08, 2019
I want to add version to my program.
I have configurated my version file "version.txt",  but I dont know how link this file to my program. If Need spec file, please send the exemple code of spec. Or is is possible add version file by dmd command line or resources. Thank you.
December 08, 2019
On Sunday, 8 December 2019 at 20:50:05 UTC, Marcone wrote:
> I want to add version to my program.
> I have configurated my version file "version.txt",  but I dont know how link this file to my program. If Need spec file, please send the exemple code of spec. Or is is possible add version file by dmd command line or resources. Thank you.

I'm not sure I know what you're asking, but maybe this is
the answer.

In version.txt:

  0.1.0 - a version example

In version.d:

  import std.string : chomp;

  immutable Version = import("version.txt").chomp;

  void main() {
      import std.stdio : writeln;
      writeln("Version: ", Version);
  }

To compile and run with both files in the current directory:

  dmd -J. -run version

With output:

  Version: 0.1.0 - a version example

The corresponding dub setting is probably stringImportPaths
December 08, 2019
On Sunday, 8 December 2019 at 20:50:05 UTC, Marcone wrote:
> I want to add version to my program.
> I have configurated my version file "version.txt",  but I dont know how link this file to my program. If Need spec file, please send the exemple code of spec. Or is is possible add version file by dmd command line or resources. Thank you.

If you have a compiled Windows resource file (resources.res), you can pass it to DMD like any source file (dmd foo.d bar.d resources.res...).
December 08, 2019
On Sunday, 8 December 2019 at 20:56:05 UTC, mipri wrote:
> On Sunday, 8 December 2019 at 20:50:05 UTC, Marcone wrote:
>> I want to add version to my program.
>> I have configurated my version file "version.txt",  but I dont know how link this file to my program. If Need spec file, please send the exemple code of spec. Or is is possible add version file by dmd command line or resources. Thank you.
>
> I'm not sure I know what you're asking, but maybe this is
> the answer.
>
> In version.txt:
>
>   0.1.0 - a version example
>
> In version.d:
>
>   import std.string : chomp;
>
>   immutable Version = import("version.txt").chomp;
>
>   void main() {
>       import std.stdio : writeln;
>       writeln("Version: ", Version);
>   }
>
> To compile and run with both files in the current directory:
>
>   dmd -J. -run version
>
> With output:
>
>   Version: 0.1.0 - a version example
>
> The corresponding dub setting is probably stringImportPaths

How can I add this "version.txt":

VSVersionInfo(
    ffi=FixedFileInfo(
        filevers=(1,0,0,0), # Version Number.
        prodvers=(1,0,0,0), # Version Number.
        mask=0x3f,
        flags=0x0,
        OS=0x40004,
        fileType=0x1,
        subtype=0x0,
        date=(0, 0)
    ),
    kids=[
    StringFileInfo(
        [
        StringTable(
            '040904b0',
            [
            #StringStruct('Comments', ''), # Description Information.
            #StringStruct('CompanyName', ''), # Description Information.
            StringStruct('FileDescription', 'Programa'), # Description Information.
            StringStruct('FileVersion', ' 1,0,0'), # Version Number.
            #StringStruct('InternalName', ''), # Description Information.
            StringStruct('LegalCopyright', 'Copyright 2019 Marcone'), # Description Information.
            #StringStruct('LegalTrademarks', ''), # Description Information.
            #StringStruct('OriginalFilename', ''), # Description Information.
            StringStruct('ProductName', 'Programa'), # Description Information.
            StringStruct('ProductVersion', ' 1,0,0'), # Version Number.
            ]
        )
        ]
    ),
    VarFileInfo(
        [
        VarStruct('Translation', [1033, 1200])
        ]
    )
    ]
)
December 10, 2019
On Sunday, 8 December 2019 at 20:50:05 UTC, Marcone wrote:
> I want to add version to my program.
> I have configurated my version file "version.txt",  but I dont know how link this file to my program. If Need spec file, please send the exemple code of spec. Or is is possible add version file by dmd command line or resources. Thank you.

Your version.txt file is python specific, it will not work in D.

You have 2 options:
- create a .res file in Visual Studio and edit it by adding a VERSIONINFO resource.
- create a .rc file in any text editor adding a VERSIONINFO resource; compile it to .res using rc yourfile.rc

Pass the .res file to the dmd compiler in the command line.
December 10, 2019
On Tuesday, 10 December 2019 at 07:23:00 UTC, rumbu wrote:
> On Sunday, 8 December 2019 at 20:50:05 UTC, Marcone wrote:
>> I want to add version to my program.
>> I have configurated my version file "version.txt",  but I dont know how link this file to my program. If Need spec file, please send the exemple code of spec. Or is is possible add version file by dmd command line or resources. Thank you.
>
> Your version.txt file is python specific, it will not work in D.
>
> You have 2 options:
> - create a .res file in Visual Studio and edit it by adding a VERSIONINFO resource.
> - create a .rc file in any text editor adding a VERSIONINFO resource; compile it to .res using rc yourfile.rc
>
> Pass the .res file to the dmd compiler in the command line.

To add to Rumbo's comment: to compile a *.rc to *.res file you will need a resource compiler.

Digital Mars's C/C++ tools [1] include one, but I suspect only for x86.

But, if you are on Windows, all of the recent Windows SDKs bundle the resource compiler as well - in both x86 and x64 versions.

On my PC I have rc.exe as part of SDK v7.1...
c:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\Bin\RC.Exe
c:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\Bin\x64\RC.Exe

..as well as part of SDK v8.1:
c:\Program Files (x86)\Windows Kits\8.1\bin\x64\rc.exe
c:\Program Files (x86)\Windows Kits\8.1\bin\x86\rc.exe

I don't have SDK 10 installed, but that will probably also contain it.

You should be able to get the individual SDKs from [2] or as part of a Visual Studio download.

[1] http://ftp.digitalmars.com/bup.zip
[2] https://developer.microsoft.com/en-us/windows/downloads/sdk-archive
December 10, 2019
On Tuesday, 10 December 2019 at 07:23:00 UTC, rumbu wrote:
> On Sunday, 8 December 2019 at 20:50:05 UTC, Marcone wrote:
>> I want to add version to my program.
>> I have configurated my version file "version.txt",  but I dont know how link this file to my program. If Need spec file, please send the exemple code of spec. Or is is possible add version file by dmd command line or resources. Thank you.
>
> Your version.txt file is python specific, it will not work in D.
>
> You have 2 options:
> - create a .res file in Visual Studio and edit it by adding a VERSIONINFO resource.
> - create a .rc file in any text editor adding a VERSIONINFO resource; compile it to .res using rc yourfile.rc
>
> Pass the .res file to the dmd compiler in the command line.

Can you send me the exemple code of VERSIONINFO in Dlang?
December 10, 2019
On Tuesday, 10 December 2019 at 09:48:11 UTC, ShadoLight wrote:
> On Tuesday, 10 December 2019 at 07:23:00 UTC, rumbu wrote:
>> [...]
>
> To add to Rumbo's comment: to compile a *.rc to *.res file you will need a resource compiler.
>
> [...]

Hi, I compile resource using windres.exe of MinGW, Can you send me the versionfile code mode to Dlang? Thank you.
December 10, 2019
On Tuesday, 10 December 2019 at 14:33:41 UTC, Marcone wrote:
> On Tuesday, 10 December 2019 at 09:48:11 UTC, ShadoLight wrote:
>> On Tuesday, 10 December 2019 at 07:23:00 UTC, rumbu wrote:
>>> [...]
>>
>> To add to Rumbo's comment: to compile a *.rc to *.res file you will need a resource compiler.
>>
>> [...]
>
> Hi, I compile resource using windres.exe of MinGW, Can you send me the versionfile code mode to Dlang? Thank you.

I'm not a 100% sure what you mean, but note there isn't a specific version "file format" (or something) that specifically applies for "dlang apps only" - the format of a *.res applies to all executables runnable on a specific platform (eg. EXEs, DLLs, etc on Windows in this case).

You can use the same resource compiler to compile a *.rc to a *.res file and link this with *.objs files produced in any native language (C/C++/D/Pascal/etc) to create your EXE/DLL.

Here, for example, is a kind of minimalist *.rc file from an old x86 app I did ages ago (edited to hide real names, etc):

////////////////////////////////////////////////////////
101 ICON DISCARDABLE ".\\Resources\\someicon.ico"

205 BITMAP DISCARDABLE ".\\Resources\\somebitmap.bmp"

STRINGTABLE DISCARDABLE
BEGIN
	3001 "This string was loaded from the resource!"
END

/////////////////////////////////////////////////////////////////////////////
//
// Version
//
VS_VERSION_INFO VERSIONINFO
 FILEVERSION 2,0,1,2
 PRODUCTVERSION 2,0,0,1
 FILEFLAGSMASK 0x3fL
 #ifdef _DEBUG
 FILEFLAGS 0x1L
#else
 FILEFLAGS 0x0L
#endif
FILEOS 0x4L
 FILETYPE 0x1L
 FILESUBTYPE 0x0L
BEGIN
    BLOCK "StringFileInfo"
    BEGIN
        BLOCK "040904b0"
        BEGIN
            VALUE "Comments", "\0"
            VALUE "CompanyName", "My Super Co\0"
            VALUE "FileDescription", "Blah blah\0"
            VALUE "FileVersion", "2, 0, 1, 2\0"
            VALUE "InternalName", "MyApp\0"
            VALUE "LegalCopyright", "Copyright (C) 2011\0"
            VALUE "LegalTrademarks", "\0"
            VALUE "OriginalFilename", "MyApp.exe\0"
            VALUE "PrivateBuild", "\0"
            VALUE "ProductName", "Blah blah\0"
            VALUE "ProductVersion", "2, 0, 0, 1\0"
            VALUE "SpecialBuild", "\0"
        END
    END
    BLOCK "VarFileInfo"
    BEGIN
        VALUE "Translation", 0x409, 1200
    END
END
////////////////////////////////////////////////////////

You can create the *.rc file by hand, but it is probably easier just to use a freely available Resource editor. The above *.rc file, IIRC, was created with XN Resource editor [1], but this was long ago and nowadays I just typically use the one that is bundled as part of Visual Studio.

Linking to a *.res file such as the one above will include the resources directly in your EXE, and you then load the resources during runtime using the listed "resource identifiers" (for example 3001 for the string).

Regarding the version info - it will be automatically displayed when you right-click the EXE (or DLL!) and select Properties. But this is a feature of Windoxs, not your app. To display the version info in your app (for example to display "My App v1.0.0.2" instead of just "My App" in the Title-bar) you need to do a little bit more work - you need to call the Windows API GetFileVersionInfo function [2] to extract the version info. Look at this [3] page for an example - it is in C but should be easy to adapt.

[1] https://stefansundin.github.io/xn_resource_editor/
[2] https://docs.microsoft.com/en-us/windows/win32/api/winver/nf-winver-getfileversioninfoa?redirectedfrom=MSDN
[3] https://stackoverflow.com/questions/940707/how-do-i-programmatically-get-the-version-of-a-dll-or-exe-file

December 10, 2019
On Sunday, 8 December 2019 at 20:50:05 UTC, Marcone wrote:
> I want to add version to my program.
> I have configurated my version file "version.txt",  but I dont know how link this file to my program. If Need spec file, please send the exemple code of spec. Or is is possible add version file by dmd command line or resources. Thank you.

I found this solution:

I created a resources.rc file with this content below and compiled with command: "windres resources.rc resource.res" and link to program with this command: "dmd source.d resource.res"

2 ICON icon.ico
1 VERSIONINFO
    FILEVERSION    1,0,0,0
    PRODUCTVERSION 1,0,0,0
{
    BLOCK "StringFileInfo"
    {
        BLOCK "040904b0"
        {
            VALUE "CompanyName",        "ACME Inc.\0"
            VALUE "FileDescription",    "MyProg\0"
            VALUE "FileVersion",        "1.0.0.0\0"
            VALUE "LegalCopyright",     "© 2013 ACME Inc. All Rights Reserved\0"
            VALUE "OriginalFilename",   "MyProg.exe\0"
            VALUE "ProductName",        "My Program\0"
            VALUE "ProductVersion",     "1.0.0.0\0"
        }
    }
    BLOCK "VarFileInfo"
    {
        VALUE "Translation", 0x409, 1200
    }
}