在自定义操作中获取 setup.exe 的位置

发布于 2024-07-17 11:33:42 字数 796 浏览 2 评论 0原文

C# 2005

我正在使用安装程序类,因为我需要一个自定义操作来读取 xml 配置文件。

因此,当用户双击安装程序时,同一文件夹中将会有一个 config.xml 文件。 我想在安装事件中阅读此 config.xml 文件。 该文件夹将包含 setup.exe 和 config.xml

但是,它无法找到 config.xml 文件,因为它在 C:\windows\system32 下查找它。 我通过使用 applicationstartup.path 发现了这一点。 但是,包含 setup 和 config.xml 的 setup 文件夹位于我的桌面上。

我以为它会在当前位置寻找它。 这将是安装文件夹。

困难在于我的安装文件夹将从互联网下载,任何用户都可以下载它并将其解压缩到计算机上的任何位置。

这是我的安装事件的代码片段。

非常感谢您的任何建议

protected override void OnAfterInstall(System.Collections.IDictionary savedState)
    {
        DataTable dt = new DataTable();
        MessageBox.Show(Application.StartupPath.ToString());
        dt.ReadXml("config.xml");

        MessageBox.Show(base.Context.Parameters["CAT_TargetDir"].ToString());
    } 

C# 2005

I am using a installer class as I need a custom action that will read in a xml config file.

So when the user double clicks the setup, there will be a config.xml file in the same folder. I would like to read in this config.xml file on install event. The folder will contain setup.exe and config.xml

However, it can't find the config.xml file as it is looking for it under C:\windows\system32. I found this out by using applicationstartup.path. However, the setup folder which contains the setup and config.xml is located on my desktop.

I thought it will look for it in the current location. Which would be the setup folder.

The difficulty is that my setup folder will be downloaded from the Internet and any user could download it and unzip it anywhere on their computer.

Here is my code snippet for the on install event.

Many thanks for any advice

protected override void OnAfterInstall(System.Collections.IDictionary savedState)
    {
        DataTable dt = new DataTable();
        MessageBox.Show(Application.StartupPath.ToString());
        dt.ReadXml("config.xml");

        MessageBox.Show(base.Context.Parameters["CAT_TargetDir"].ToString());
    } 

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

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

发布评论

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

评论(4

少女净妖师 2024-07-24 11:33:43

假设您正在谈论 MSI,那不是 OriginalDatabase 属性?

Assuming you're talking about an MSI, isn't that the OriginalDatabase property?

半步萧音过轻尘 2024-07-24 11:33:43

假设您没有错误地输入 CAT_TargetDir 而不是 TARGETDIR,您可以执行以下解决方法:设置 CustomActionData 并将 TARGETDIR 作为参数传递给自定义操作。 这不是最优雅的解决方案,但它应该很容易工作。

Supposing you're not mistyping CAT_TargetDir instead of TARGETDIR you can do the following work-around: set a CustomActionData and pass TARGETDIR as the argument to your Custom action. It's not the most elegant solution but it should work pretty easy.

西瑶 2024-07-24 11:33:43

我设法解决了这个问题。

答案只是编写一个简单的bat 文件来为我完成所有工作。 然后bat文件将调用安装程序并安装应用程序。

谢谢,

I am managed to solve this.

The answer was just to write a simple bat file that will do all the work for me. Then the bat file will call the setup and install the application.

Thanks,

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