使用 WiX 获取 INI 文件值

发布于 2024-07-29 13:05:35 字数 712 浏览 5 评论 0原文

我想从 WiX 安装程序中的 INI 文件读取值。 我刚刚尝试使用 IniFileSearch,但这会查找 INI 文件或 INI 文件中指定的路径(文档不清楚),它不会从 INI 读取值文件。

我需要定制才能执行此操作吗? 如果是这样,人们会有何建议? 不过,如果 WiX 没有这个功能,那就太奇怪了!

我正在使用的代码:

<Property Id="SP">
    <IniFileSearch Id="SearchSPVersion" Name="sp.ini" Section="ServicePack"
    Key="Version" Type="raw">
        <DirectorySearch Id="SPIniFilePath" Path="[CFGPATH]">
            <FileSearch Id="SPIniFile" Name="sp.ini"/>
        </DirectorySearch>
    </IniFileSearch>
</Property>

INI 文件:

[ServicePack] 
Version=1 

我尝试过使用和不使用目录和文件搜索(使用“名称”中的完整路径),并且尝试过 type =“raw”、“file”和“directory”。

I'd like to read a value from an INI file in a WiX installer. I've just tried to use IniFileSearch, but this looks for an INI file or a path specified in an INI file (the documentation isn't clear), it doesn't read a value from an INI file.

Do I need a customaction to do this? And if so, what would people suggest? Seems very strange if WiX doesn't have this, though!

Code I'm using:

<Property Id="SP">
    <IniFileSearch Id="SearchSPVersion" Name="sp.ini" Section="ServicePack"
    Key="Version" Type="raw">
        <DirectorySearch Id="SPIniFilePath" Path="[CFGPATH]">
            <FileSearch Id="SPIniFile" Name="sp.ini"/>
        </DirectorySearch>
    </IniFileSearch>
</Property>

INI file:

[ServicePack] 
Version=1 

I've tried with and without the directory and file search (using full path in 'name'), and I've tried type = "raw", "file" and "directory".

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

泪眸﹌ 2024-08-05 13:05:35

Windows Installer 文档 指出 .ini文件必须存在于默认的 Microsoft Windows 目录中。

这有点令人困惑,因为 FileSearch 和 DirectorySearch 是有效的 WiX 子项,但我相信这是为了搜索 INI 文件本身内指定的文件或目录。 您会注意到可以在 INI 文件中搜索的三种类型的值是目录、文件和原始值。

这是 Windows Installer 的限制,而不是 WiX 的限制。 用于读取 INI 文件的 Microsoft 接口(例如 GetPrivateProfileString) 如果未指定路径,则查找 Windows 文件夹。 我猜 Windows Installer 团队决定不简化事情,只支持 Windows 文件夹中的 INI 文件,不允许动态路径。

The Windows Installer documentation states that the .ini file must be present in the default Microsoft Windows directory.

It's a bit confusing as FileSearch and DirectorySearch are valid WiX children, however I believe this is for searching for a file or directory specified within the INI file itself. You'll notice the three types of values you can search for within an INI file are directory, file and raw.

It's a limitation of Windows Installer, not of WiX. The Microsoft interfaces for reading INI files (e.g. GetPrivateProfileString) looks in the Windows folder if a path is not specified. I guess the Windows Installer team decided not to simplify things and only support INI files in the Windows folder by not allowing a dynamic path.

穿越时光隧道 2024-08-05 13:05:35

我知道这是一个旧线程,但我希望能让某人摆脱我所经历的同样的痛苦......

这确实从 ini 文件中读取了一个值,至少就我的测试而言是这样与 Wix3.5 和 3.6 测试版。 即,

<Property Id="MY_PROPERTY">
        <IniFileSearch Id="myIniSearch" Name="myConfigFile.ini" Section="section1" Key="name" Type="raw" />
    </Property>

    <Condition Message="myconfigfile not def.">MY_PROPERTY</Condition>

将相应的 ini 文件保存在 C:\windows\myConfigFile.ini (Windows 7) 中:

[section1]
name=testing

但是,我花了很多时间试图弄清楚为什么这似乎不起作用,然后才意识到 ini 文件必须是 ANSI< /strong> 而不是 UTF8! 位于正确位置(即 c:\Windows\some.ini)的 ANSI 编码 .ini 文件将起作用。

UTF8 文件只是不会被读取,不会发生错误,属性分配也不会发生。

I know this is an old thread, but I was hoping to save someone from the same pain I went through....

This does read a value from an ini file, at least so far as my tests with Wix3.5 and 3.6 beta. i.e.

<Property Id="MY_PROPERTY">
        <IniFileSearch Id="myIniSearch" Name="myConfigFile.ini" Section="section1" Key="name" Type="raw" />
    </Property>

    <Condition Message="myconfigfile not def.">MY_PROPERTY</Condition>

With the corresponding ini file saved in C:\windows\myConfigFile.ini (Windows 7) :

[section1]
name=testing

However, I burned many hours trying to figure out why this appeared to not work before realising that the ini file must be ANSI and not UTF8! An ANSI encoded .ini file in the correct location i.e. c:\Windows\some.ini will work.

UTF8 files are just not read, no error occurs, the property assignment just doesn't happen.

咋地 2024-08-05 13:05:35

在 DTF 自定义操作中尝试此操作:
C# 中的 INI 文件读取器

Try this in a DTF custom action:
INI File Reader in C#

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文