修改 MSI 数据库属性的问题 [英] Problem with modifying an MSI database property
问题描述
我需要通过 C# 修改 Upgrade
MSI 表的 UpgradeCode
属性.此代码适用于其他表的属性,但在我尝试修改这些属性时会引发错误.
I need to modify the UpgradeCode
property of the Upgrade
MSI table via C#.
This code works ok with other tables' properties, but throws an error when I'm trying to modify these.
using (var database = new Database(TEMPDATABASE, DatabaseOpenMode.Direct))
{
string upgradeCode = Guid.NewGuid().ToString("B").ToUpper();
database.Execute("Update `Upgrade` Set `Upgrade`.`UpgradeCode` = '{0}'", upgradeCode);
}
错误是:
Microsoft.Deployment.WindowsInstaller.InstallerException: '函数在执行过程中失败.'
Microsoft.Deployment.WindowsInstaller.InstallerException: 'Function failed during execution.'
推荐答案
我感到好奇和掠夺 github.com - 它给出了以下内容:完整项目 - 只需将其作为一个整体下载即可.
I got curious and pillaged github.com - and it giveth the following: Full project - just download it as a whole.
实际代码是(github.com 上的文件中的一些 unicode 换行问题,我已修复他们在这里):
The actual code was (some unicode line feed issues in the file on github.com, I have fixed them up here):
public static void UpdateUpgradeTable(this Database db, Guid upgradeCode)
{
using (View view = db.OpenView("SELECT * FROM `Upgrade`", new object[0]))
{
view.Execute();
using (Record record = view.Fetch())
{
record[1] = upgradeCode.ToString("B").ToUpperInvariant();
view.Replace(record);
}
db.Commit();
}
}
我根据上面的内容制作了以下模型(非常丑陋,但确实有效):
I took the above and made the following mock-up (very ugly, but it worked):
using (Database db = new Database(@"C:\Test.msi", DatabaseOpenMode.Direct))
{
using (View view = db.OpenView("SELECT * FROM `Upgrade`", new object[0]))
{
view.Execute();
using (Record record = view.Fetch())
{
record[1] = "{777888DD-1111-1111-1111-222222222222}";
record[2] = "";
record[3] = "4.0.1";
record[4] = "";
record[5] = "1";
record[6] = "";
record[7] = "WIX_UPGRADE_DETECTED";
view.Replace(record);
}
db.Commit();
using (Record record = view.Fetch())
{
record[1] = "{777888DD-1111-1111-1111-222222222222}";
record[2] = "";
record[3] = "";
record[4] = "4.0.1";
record[5] = "1";
record[6] = "";
record[7] = "WIX_DOWNGRADE_DETECTED";
view.Replace(record);
}
db.Commit();
}
}
这篇关于修改 MSI 数据库属性的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!