如何在 C# 中解析 MSI 路径? [英] How can I resolve MSI paths in C#?

查看:20
本文介绍了如何在 C# 中解析 MSI 路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在安装之外从 MSI 数据库解析目标路径.我目前正在使用 Wix SDK 通过查询数据库的目录和文件表并从那里构造路径来执行此操作,但解析路径似乎应该已经内置.是否有图书馆可以做到这一点,甚至是非官方的,还是我坚持自己做?

I need to resolve target paths from an MSI database, outside of the installation. I am currently doing this using the Wix SDK by querying the database's Directory and File tables and constructing the paths from there, but resolving paths seems like something that should already be built-in. Is there a library that does this, even something unofficial, or am I stuck with doing it on my own?

此问题已被询问C++,但唯一的答案不知何故误解了关于字符串的问题.

This question has already been asked for C++, but the only answer somehow misunderstood the question to be about strings.

我真的不介意表演.我真正关心的是解决特殊文件夹,如.:Fonts"、.:Windows"、.:WinRoot"等——我仍然可以在自己的代码中完成,但不是很优雅.

I don't really mind performance. My real concern is with resolving special folders like ".:Fonts", ".:Windows", ".:WinRoot", etc. - which I can still do in my own code but not very elegantly.

推荐答案

DTF刚出来的时候我做了和你一样的事情.我编写了所有查询和循环来获取我正在处理的数据.而且表演有点痛苦.

I did the same thing you did when DTF first came out. I wrote all the queries and loops to get the data I was working for. And the performance was kind of painful.

然后我注意到 Microsoft.Deployment.WindowsInstaller.Package 程序集中的 InstallPackage 类.当我看到以下代码使用该类的速度和简单程度时,我感到有点傻:

Then I noticed the InstallPackage class in the Microsoft.Deployment.WindowsInstaller.Package assembly. I felt kind of silly when I saw how fast and simple the following code is using that class:

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();
            }
        }
    }
}

这篇关于如何在 C# 中解析 MSI 路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆