Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.3k views
in Technique[技术] by (71.8m points)

windows installer - How to parameterize msi file from electron builder

I'm trying to create an .msi installer file with electron-builder (version 20.39.0), that can be parameterized during install time. The parameters (e.g. server endpoint) should be written in a file.

Example:
when MsiExec /i "MyProject.msi" SERVER_ENDPOINT=myapp.example.com
then myapp.example.com should appear in a file in the installation dir.

I tried to edit electron-builder's wix template file adding the following to write ${SERVER_ENDPOINT} to server.txt

File C:...MyProject ode_moduleselectron-builder-libemplatesmsiemplate.xml

...
<CustomAction Id="writeConfigFile" Directory="APPLICATIONFOLDER" Execute="commit" Impersonate="yes" ExeCommand="cmd.exe /c &quot;echo ${SERVER_ENDPOINT} > server.txt&quot;" Return="check" />
...
<InstallExecuteSequence>
  ...
  <Custom Action="writeConfigFile" After="InstallFinalize"/>
</InstallExecuteSequence>

Running with

MsiExec /i "MyProject.msi" /L*v Install.log SERVER_ENDPOINT=myapp.example.com

I does not work yet. It installs but does not show writeConfigFile in the log file.

Do you think this is the right approach to make the msi file parameterized?
Or would you recommend another solution?

I also found Orca.exe, to create an MST file, but I would prefer a simple solution, without manual steps.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Setting MSI Properties

I am unfamiliar with Electron builder. However, in MSI terms you need to specify that the content in the file should be replaced by an MSI Property, and then you need to set the property either in a transform, by command line or in the property table (embedded in MSI).

In fact you can set all three at once, and I am not sure which one would apply :-). Command line certainly overrides the property table, but I am not sure what wins in a battle between a transform and a command line parameter:

Transform (applying transform on command line, actual settings inside the transform file - mst):

msiexec.exe /i "MySetup.msi" TRANSFORMS="MyTransform.mst"

Command Line (setting PUBLIC properties on the command line):

msiexec.exe /i "MySetup.msi" MYPROPERTY="My Value here"

Property Table (the built-in Property table in every MSI can also have a value set):

Property Table


Using MSI Properties

Setting properties is obviously not enough, you have to define where the value goes during installation.

  • If the file is an INI file it is quite easy to set a parameter, since this is a built-in feature of MSI.
  • XML file updates and text file updates are worse because then you rely on third-party solutions or you do it yourself via custom actions (I would not do the latter).

Advanced Installer has very nice features to replace parameters in XML and text files. Installshield also has such features. The open source WiX toolkit also has features to support XML file updates, but it is much more involved than the commercial tools.

With regards to Electron I don't know how it works. But, in either case the central task is to get the MSI to contain a construct such as this:

Advanced Installer

This is from an MSI compiled with Advanced Installer. You see that I have a parameterized value [MYVALUE]. It can be set on the command line since it is an ALL UPPERCASE property - also known as a PUBLIC MSI property. During installation the property in braces will be replaced by the value passed in. Obviously.


Some Links:


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...