0

I am new to Powershell. I am using power shell script to build VB6 dlls.

$compiler = "C:\Program Files (x86)\Microsoft Visual Studio\VB98\VB6.EXE".
$vbpPath= "C:\...\Desktop\ProjectFile\ProjectName.vbp"
$Outputpath = "C:\...\Desktop\Destination\ProjectName.dll"

Start-Process -FilePath "`"$compiler `"" -ArgumentList "/out
error.txt /make `"$vbpPath`" `"$Outputpath `""  -PassThru -Wait

Can we set its product version by our self when we build it? Let's say set product version to "Mysoftware 5.1 Beta 6". Thanks in advance.

Alden Ken
  • 142
  • 8
  • From memory (and I don't have a working copy of VB6 any more), there isn't a command line option to set product versions. Your best bet may be to script an update to the VBP file or to use a utility to set the version number after the build. – OldBoyCoder Jul 06 '16 at 08:53
  • Hi, Thanks for your reply :), I am using TFS server to run it and the expected output i hope is the product version can be automatic update, the best will be update it after built as i got a lot of dlls and exes from different compiler need to be update. – Alden Ken Jul 11 '16 at 01:22

1 Answers1

0

Hi to anyone who faced similar issues,

After referencing this link: How do I set the version information for an existing .exe, .dll?

I was able to change dlls and exes' product version under a specific folder. This step is done after all the dlls and exes were built.

  1. Use Resource Hacker to Extract the *.RC file from exes/ dlls :

    $ResourceHackerPath = "C:\Tools\resource_hacker\ResourceHacker.EXE"
    $Dllpath = "...\MySoftware\Mydll.dll" 
    $RCpath = "...\MySoftware\Mydll.RC"
    Start-Process -FilePath "`"$ResourceHackerPath`""  -ArgumentList "-extract `"$ProductPath`",`"$RCpath`",versioninfo,," -wait                                                                          
    
  2. Edit product version in *.RC file :

    $OriProVer = (Get-Item -literalpath $Dllpath ).VersionInfo.ProductVersion
    $NewProVer = "Mysoftware 5.1 Beta 6"
    (Get-Content $Dllpath).Replace($OriProVer, $NewProVer ) | Set-Content $Dllpath
    
  3. Use GoRC to change *.RC file format to *.RES file:

    Start-Process -FilePath "`"$GoRCPath`""  -ArgumentList "/r `"$RCpath`"" -wait
    
  4. Use Resource Hacker again to add the *.RES file to the dlls or exes

    $RESpath = "...\MySoftware\Mydll.RES"
    Start-Process -FilePath "`"$ResourceHackerPath`""  -ArgumentList "-addoverwrite  `"$Dllpath `",`"$Dllpath `",`"$RESpath`", , ," -wait
    

Your dlls' product version should be updated to any string that you want.

Extra tips, if you wish to update a lot of dlls and exes product version: You can try this:

  1. Search all the dlls and exes under a specific folder:

    $directory = "...\Desktop\New Folder"
    $FileNameList = Get-ChildItem -literalpath  $directory -Include *.dll, *.exe  -recurse | foreach-object { "{0}" -f [System.Diagnostics.FileVersionInfo]::GetVersionInfo($_).FileName}
    
  2. Doing the all 4 steps above in a for loop:

    for ($i = 0;$i -lt $FileNameList.count;$i++){...}
    

Thanks & have a nice day :)

Community
  • 1
  • 1
Alden Ken
  • 142
  • 8