How can I resolve MSI paths in C#?(如何在 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 路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在 C# 中解析 MSI 路径?


- C#MongoDB使用Builders查找派生对象 2022-09-04
- MoreLinq maxBy vs LINQ max + where 2022-01-01
- WebMatrix WebSecurity PasswordSalt 2022-01-01
- C# 中多线程网络服务器的模式 2022-01-01
- 良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 2022-01-01
- 输入按键事件处理程序 2022-01-01
- Web Api 中的 Swagger .netcore 3.1,使用 swagger UI 设置日期时间格式 2022-01-01
- 带有服务/守护程序应用程序的 Microsoft Graph CSharp SDK 和 OneDrive for Business - 配额方面返回 null 2022-01-01
- 在哪里可以找到使用中的C#/XML文档注释的好例子? 2022-01-01
- 如何用自己压缩一个 IEnumerable 2022-01-01