DEV Community

abdfn
abdfn

Posted on • Updated on

Create a .msi file for go program

Hi everyone, long time no write anything, but I had a lot of projects and stresses to study, but now, we'll create a .msi file for go program

Pre-requisites

What's we'll use?

Package go-msi helps to generate MSI package for a Go project.

installation

by go

go get github.com/mh-cbon/go-msi
Enter fullscreen mode Exit fullscreen mode

by Chocolatey

choco install go-msi
Enter fullscreen mode Exit fullscreen mode

for more, visit https://mh-cbon.github.io/go-msi/#install

ok, now let's create a simple go file msi.go

package main

import "fmt"

func main() {
  fmt.Println("Gen MSI File")
}
Enter fullscreen mode Exit fullscreen mode

build it

go build
Enter fullscreen mode Exit fullscreen mode

wix.json

to create a .msi file, we need wix.json

{
  "product": "YOUR_PRODUCT_NAME",
  "company": "YOUR_COMPANY_NAME",
  "license": "LICENSE",
  "upgrade-code": "",
  "files": {
    "guid": "",
    "items": [
      "path/to/msi.exe",
    ]
  },
  "env": {
    "guid": "",
    "vars": [
      {
        "name": "PATH",
        "value": "[INSTALLDIR]",
        "permanent": "no",
        "system": "no",
        "action": "set",
        "part": "last"
      }
    ]
  },
  "shortcuts": {},
  "choco": {
    "description": "YOUR_DESC",
    "project-url": "YOUR_PROJECT_URL",
    "tags": "TAGS YOU NEED",
    "license-url": "YOUR_LICENSE_URL"
  }
}
Enter fullscreen mode Exit fullscreen mode

our guid props are empty, run this command

go-msi set-guid
Enter fullscreen mode Exit fullscreen mode

Create Interfaces

we'll create three user interfaces

  1. License Agreement Page
  2. WiX UI
  3. Product Page

now create three files

  • LicenseAgreementDlg_HK.wsx
  • product.wsx
  • WixUI_HK.wsx

download these files here

put these files in folder, like templates folder

Generate

go-msi make --msi YOUR_PRODUCT_NAME.msi --version YOUR_VERSION -s ./path/to/*.wsx
Enter fullscreen mode Exit fullscreen mode

now you can test your msi file

๐Ÿ‘‹

Top comments (4)

Collapse
 
psteffensen profile image
psteffensen

Thank you for this tutorial. It works!

What can I do if I want to run one of my exe files during or after the install?

Collapse
 
psteffensen profile image
psteffensen • Edited

I got it working. I got help from this: wixtoolset.org/documentation/manua...

So the end of product.wxs looks like this now:

   <UI>
        <!-- Define the installer UI -->
        <UIRef Id="WixUI_HK" />
        <Publish Dialog="ExitDialog"
            Control="Finish"
            Event="DoAction"
            Value="LaunchApplication">WIXUI_EXITDIALOGOPTIONALCHECKBOX = 1 and NOT Installed
        </Publish>
    </UI>

    <Property Id="WIXUI_INSTALLDIR" Value="INSTALLDIR" />
    <Property Id="WIXUI_EXITDIALOGOPTIONALCHECKBOXTEXT" Value="Install Measurement Server Service" />
    <Property Id="WIXUI_EXITDIALOGOPTIONALCHECKBOX" Value="1"/>

    <!-- this should help to propagate env var changes -->
    <CustomActionRef Id="WixBroadcastEnvironmentChange" />

     <Property Id="WixShellExecTarget" Value="[#ApplicationFile1]" />
     <CustomAction Id="LaunchApplication"
         BinaryKey="WixCA"
         DllEntry="WixShellExec"
         Impersonate="yes" />

</Product>
Enter fullscreen mode Exit fullscreen mode
Collapse
 
abdfnx profile image
abdfn

nice

Collapse
 
efmanu profile image
Manu Francis

Nice tutorial.

One question, how can I modify wix.json for storing error logs of installed app to a file?