1

I am trying to make use of the WiX library to do some machine product analysis for a project I am on. I am scratching my head as to why this is absent from the class in the title?

Is there a way to get this from the WiX library that I am missing? I know how to do it with msi.dll interop, but wanted to try to do everything from the one library. It just seems odd to me that such a key part of an MSI package is missing.

WiX version is 3.5.2519.0

4
  • So, I dug deeper, and I don't like it, but it works...I did: // snarky comment goes here for missing UpgradeCode in the ProductInstallation class... string upgradeCode; using (Database db = new Database(installation.LocalPackage, DatabaseOpenMode.ReadOnly)) { upgradeCode = (string)db.ExecuteScalar("SELECT Value FROM Property WHERE Property = 'UpgradeCode'"); } Console.WriteLine("UpgradeCode: {0}", upgradeCode); Commented Jan 19, 2012 at 21:55
  • I explained why UpgradeCode isn't there. If it really bothers you that much you could write an extension method. Commented Jan 20, 2012 at 11:51
  • I think we have a timing issue here. I posted my comment before I ever saw your answer, Christopher. It's all good. I am just surprised that with all the other fields there that the root method ( MsiGetProductInfo) does not return the UpgradeCode since it is such an important part of a product after all. Commented Jan 20, 2012 at 14:05
  • I see your point but actually UpgradeCode is less important then PackageCode and ProductCode. In fact, it's only strongly reccomended that an MSI has an UpgradeCode. It's actually not a required property at all and is only needed and used if you plan on using the Upgrade table. You can install products that don't have an UpgradeCode but you can't install products that don't have a ProductCode or PackageCode. Commented Jan 20, 2012 at 15:49

1 Answer 1

3

The ProductInstallation class encapsulates the MsiGetProductInfo function found in Msi.dll. Since this function doesn't expose UpgradeCode neither does ProductInstallation.

ProductInstallation does have the InstallSource member (INSTALLPROPERTY_INSTALLSOURCE equiv ) and you can use that to construct an InstallPackage class and access it's Property accessor.

static public string GetPackageUpgradeCode(string packagePath) { string upgradeCode = string.Empty; using (InstallPackage package = new InstallPackage(packagePath, DatabaseOpenMode.ReadOnly)) { upgradeCode = package.Property["UpgradeCode"]; } return upgradeCode; } 

If you really don't want to add another refrence you can open it as a Database and use the ExecuteScalar member to select the UpgradeCode value from the Property table.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.