How can I resolve MSI paths in C#?
我需要在安装之外从MSI数据库解析目标路径。我目前正在使用Wix SDK来执行此操作,方法是查询数据库的Directory和File表并从中构造路径,但是解析路径似乎应该已经内置。是否有一个图书馆可以做到这一点,甚至是非官方的,还是我一个人坚持做呢?
这个问题已经被要求使用C了,但是唯一的答案却以某种方式误解了关于字符串的问题。
我真的不介意表演。我真正关心的是解决特殊的文件夹,例如"。:Fonts"," .: Windows"," .: WinRoot"等-我仍然可以在自己的代码中进行操作,但不太优雅。
我做了与DTF刚问世时所做的相同的事情。我编写了所有查询和循环以获取我正在使用的数据。而且表现有点痛苦。
然后,我注意到Microsoft.Deployment.WindowsInstaller.Package程序集中的InstallPackage类。当我看到以下代码使用该类的过程如此快速和简单时,我感到很傻:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | using System; using Microsoft.Deployment.WindowsInstaller; using Microsoft.Deployment.WindowsInstaller.Package; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { using (var package = new InstallPackage("foo.msi", DatabaseOpenMode.ReadOnly)) { foreach (var filePath in package.Files) { Console.WriteLine(filePath.Value); } Console.WriteLine("Finished"); Console.Read(); } } } } |