I'm trying to add a feature to my installer which would basically enable a simple copy of the file structure rather than running the entire installation process, thus killing any MSI features.
It would be controlled by a simple switch that would skip steps and jump directly to the progress dialog, which would copy the files manually.
What I need to know if it's possible to manually unpack binaries from the MSI.
All that I can see that I can call these two methods:
MsiRuntime.MsiSession.GetEmbeddedData("");
MsiRuntime.MsiSession.ReadBinary("")
And the list of files:
MsiRuntime.MsiSession.Database.ExecuteQuery("Select * from File");
What I need to know if it's possible to manually unpack binaries from the MSI.
Then it looks like MsiRuntime.MsiSession.ReadBinary("") is exactly what you need. Isn't it?
Though keep in mind that the both methods that you mentioned are reading from the Binary not File table. But this is arguebly exactly what you need. Because if you put something in File table then MSI will try to install/uninstall it and this is what you are trying to avoid.
Adding binaries is like that:
```C#
var project = new Project("MyProduct",
new Dir(@"%ProgramFiles%\My Company\My Product",
new Binary("CRTSetup.msi"),
...
```
Then it looks like MsiRuntime.MsiSession.ReadBinary("") is exactly what you need. Isn't it?
Yes, it was back when I was starting tweaking the installer. But I forgot that I had to add the binaries and I was trying to read the ones inside the File table.
In the end, for me, it was much easier to just call the installer with a feature already implemented, the administrative install (using the /a command instead of /i).
Now I even command which file should be copied using the ADDLOCAL property.
I was wrong. The installer was not actually copying the files that I was thinking it was.
The installer on administrative mode uses TARGETDIR instead of INSTALLDIR and it creates this file structure, ignoring ADDLOCAL:
* Parent Folder
⁁ MyApp.msi [Empty MSI, with no files]
* ProgramFilesFolder
⁁ All files that were inside of the installer
So, I'll have to use the Binary method. Will this increase the size of my installer?
Or, I'll keep using the administrative mode, but I manually delete files after the end of the process.
@oleg-shilo Is there any way to switch to administrative install mode after the installer is running?
I ended up using the administrative mode as a way of enabling a portable mode "installation", deleting the files that I didn't need.
But that portable mode requires execution of the installer with the a/ parameter instead of the i/.
Right now I'm trying to add a switch inside the install process, which the user can select.
Basically enabling the administrative mode from within the installer.
I found this method, which looks like it would enable that for me, but it's throwing an exception.
MsiRuntime.MsiSession.SetMode(InstallRunMode.Admin, true);
System.InvalidOperationException: 'Operation is not valid due to the current state of the object.'
Not sure...
Let's first check if the Operation is not valid... error is caused by the session object not being initialized correctly. Check if the following works
C#
MsiRuntime.MsiSession["test_dummy_prop"] = "test_dummy_value";
If it doesn't then there is something wrong with the timing of when in SetMode is called.
Otherwise there is something wrong with setting this specific mode this way.
In both cases there is a chance MSI/WiX knowledge base can revile something about it.
If you compltely hit the wall you can always implement a custom BA based bootstrapper, which will abort the install if it is not in _administrative mode_ and relaunch itself with /a arg
I discovered that it's only allowed to call SetMode with two parameters.
😞 Then a bootstrapper seems to be the only way