0

I have created msi using Wix toolset for worker service as window service. In setup project ,i have added a property in product.wxs file.

<Property Id="DF_PORT" Value="8080"/>

How can i update the value of 'DF_PORT' property using .net core. i have tried c# code below.But not working. Reference: Can't rename MSI afterwards

private string SetMsiProperty(string msiFilePath, string property, string value)
        {
            string retVal = string.Empty;

            // Create an Installer instance  
            WindowsInstaller.Installer installer = (WindowsInstaller.Installer)new Installer();

            // Open the msi file for reading  
            // 0 - Read, 1 - Read/Write  
            Database db = installer.OpenDatabase(msiFilePath, WindowsInstaller.MsiOpenDatabaseMode.msiOpenDatabaseModeTransact); //// Open the MSI database in the input file 

            // Fetch the requested property  
            string sql = String.Format("SELECT Value FROM Property WHERE Property='{0}'", property);

            View view = db.OpenView(sql); //View vw = db.OpenView(@"SELECT `Value` FROM `Property` WHERE `Property` = 'ProductVersion'");            
            view.Execute(null);

            // Read in the fetched record  
            Record record = view.Fetch();
            if (record != null)
            {
                record.set_StringData(1, value);


            }

            view.Modify(MsiViewModify.msiViewModifyReplace, record);
            view.Close();
            db.Commit();

            System.Runtime.InteropServices.Marshal.FinalReleaseComObject(record);
            System.Runtime.InteropServices.Marshal.FinalReleaseComObject(view);
            System.Runtime.InteropServices.Marshal.FinalReleaseComObject(db);

            return retVal;
        }
David
  • 380
  • 2
  • 14
  • If can the property value from command line, when invoking the installer – Pavel Anikhouski Jul 12 '20 at 18:47
  • Is there any way to update msi property using .net core? – David Jul 13 '20 at 05:24
  • 1
    A couple of links: [Modify MSI property](https://stackoverflow.com/a/57778570/129130), [TemporaryFilesExtractor](https://stackoverflow.com/a/57225970/129130), [Uninstall MSI](https://stackoverflow.com/a/52280957/129130). This is not a custom action - is it? In other words an action embedded in the MSI. – Stein Åsmul Jul 13 '20 at 15:36

0 Answers0