在自定义操作中获取 setup.exe 的位置
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
假设您正在谈论 MSI,那不是 OriginalDatabase 属性?
Assuming you're talking about an MSI, isn't that the OriginalDatabase property?
假设您没有错误地输入
CAT_TargetDir
而不是TARGETDIR
,您可以执行以下解决方法:设置 CustomActionData 并将 TARGETDIR 作为参数传递给自定义操作。 这不是最优雅的解决方案,但它应该很容易工作。Supposing you're not mistyping
CAT_TargetDir
instead ofTARGETDIR
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.我设法解决了这个问题。
答案只是编写一个简单的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,
您也可以尝试以下操作: 我需要从 MSI 源目录复制文件的 MSI 自定义操作
You can also try this: I require a MSI Custom action that copies a file from the MSI source directory