Search code examples
powershelldllvb6fileversioninfo

Power shell script - can we set dll Product Version when we build it?


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.


Solution

  • 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 :)