oleg-shilo / wixsharp

Framework for building a complete MSI or WiX source code by using script files written with C# syntax.
MIT License
1.12k stars 175 forks source link

[Question] How to access location of actual msi during installation #1625

Closed ssrakesh closed 2 months ago

ssrakesh commented 2 months ago

Problem: We have created a msi using wix#. msi is available in the portal, but while downloading we have to embed uniq info to msi and same will be used during installation and during app launch. So we are creating a zip file along with configuration file + msi in the portal for user to download. But during installation I am not able to access the msi location

I tried to use following ppt to get msi location, in ElevatedManagedAction(When.Before, Step.InstallFiles, Condition.NOT_BeingRemoved)

session.Property("CURRENTDIRECTORY"),
session.Property("SourceDir"),
session.Property("SOURCEDIR"),
session.Property("OriginalDatabase")

But these are set to empty during action execution,

how to get this property with proper values? or is there any other way to embed info into msi?

Torchok19081986 commented 2 months ago

morning, https://learn.microsoft.com/en-us/windows/win32/msi/originaldatabase?redirectedfrom=MSDN According to MS - Property of Original Database should be right way. Maybe Step is not set it correctly. Does MSI cached MSI Files into Windows Temp Folder ? if so you can try get tempfilename from installer self. Wix Toolset has dll WindowsInstaller and Class Installer. Maybe it helps. Another way debug step by step. If you use Wix# Tempalte and Temaplte for Cusotm UI, you can debug msi BeforeInstall Event with MessageBox. Here Windows Installer shows all properties which it want to set before Installation begins. You can try it.

just found by oleg https://github.com/oleg-shilo/wixsharp/issues/853.

also you can try following command msiexec /i MyProgramm.msi /l*v C:\Temp\log.txt //path to Log has to be set. In Log you can see all property and step where msi set all value for installation.

best regards, Torchok.

oleg-shilo commented 2 months ago

WixSharp added the extension method to the session object: e.Session.MsiFile();. It simply accesses the OriginalDatabase property.

ssrakesh commented 2 months ago

Thanks for the quick replay. I dont quit understand ur answer, but I have found the value of those properties empty by using session log itself and yes I am using command line installation to see the logs when I log these variables in log it shows empty, but at the end when msi dumps all the variables, could see the same variables I am using having proper values. so I dont understand what is the real issue. I have already referred #853, in the current version of wix# there is are no events like AfterIntall.

ssrakesh commented 2 months ago

WixSharp added the extension method to the session object: e.Session.MsiFile();. It simply accesses the OriginalDatabase property.

If u are referring to AfterInstall, tis method is not available in project. is it required to add any extra reference? Currently referred libs are -WixSharp. -WixSharp.bin. -WixSharp.wix.bin

session object I am using in action does not have msifile()

oleg-shilo commented 2 months ago

Object e.Session is the argument of any WixSharp installation event. Alternatively, you can access the session object from a raw managed CustomAction. It is the only argument of the CA method: public static ActionResult MyAction(Session session).

As for managed events (e.g. AfterInstall). You need to use ManagedProject instead of Project.

ssrakesh commented 2 months ago

Thanks, Is the WixSharp installation event avialable with non managed project also? I am not able to find it. Do I need to use bootstrapper?

I am accessing session from ElevatedManagedAction itself. but in log those parameters are empty.

ManagedProject is so good, bz of the UAC issue others in my team will not accept.

ssrakesh commented 2 months ago

I think best approach would be to use Wixsharp - bootstrapper with BA

ssrakesh commented 2 months ago

I tried to send param to msi, msiexec /i "myproduct.msi" SOMECONFIG="blabla" /l*ie d:\log.txt But this param is empty during execution of ElevatedManagedAction(When.Before, Step.InstallFiles, Condition.NOT_BeingRemoved).

But at the end when it dumps all the values in log, I can see proper values. So how to get param value in ElevatedManagedAction ? Do I need to enable some setting to make params accessible during action excecution?

ssrakesh commented 2 months ago

I just used ElevatedManagedAction.UsesProperties = "OriginalDatabase" then values started appearing. Another solution would be to use Self-executable_Msi template from wix samples, and do operation at the end of msi

oleg-shilo commented 2 months ago

ElevatedManagedAction.UsesProperties = "OriginalDatabase"

Please note that it is already set if you are using ManagedProject and project events (e.g. Load, BeforeInstall) instead of raw Custom Actions.