简体   繁体   English

安装程序项目自定义操作-指定工作目录

[英]Installer Project Custom Actions - Specify working directory

I have a custom action that runs as a Visual Studio Installer Projects deployment. 我有一个作为Visual Studio Installer项目部署运行的自定义操作。

Is it possible to specify the working directory of this custom action, relative to the installation directory? 是否可以相对于安装目录指定此自定义操作的工作目录?

Edit 编辑

To clarify 澄清

I have an installer project that runs a program as a custom action. 我有一个安装程序项目,它作为自定义操作来运行程序。 I want to specify the working directory of that program from within the installer project, so when the program runs during installation, it will run with the Working directory I specified at the time of creating the installer. 我想从安装程序项目中指定该程序的工作目录,因此,当程序在安装过程中运行时,它将与创建安装程序时指定的工作目录一起运行。

Working Directory : Is this an EXE custom action? 工作目录 :这是EXE自定义操作吗? Custom actions in Visual Studio Installer Projects run in deferred mode, system context - meaning they run as System / LocalSystem . Visual Studio Installer项目中的自定义操作以deferred mode, system context运行deferred mode, system context ,这意味着它们以System / LocalSystem身份运行。 I am honestly not sure what that does to the " working folder ". 老实说,我不确定该如何处理“ working folder ”。 I would assume it just means the working folder is wherever the executable is running from. 我认为这只是意味着工作文件夹位于运行可执行文件的位置。

VS Installer Project Limitations : Visual Studio Installer Projects lack the ability to configure advanced settings altogether. VS Installer项目的局限性 :Visual Studio Installer项目缺乏完全配置高级设置的能力。 There is a way to run an EXE file and specify a working folder, but it is not supported by these projects. 有一种方法可以运行EXE文件并指定工作文件夹,但这些项目不支持该方法。 I am also not sure if this would solve your problem before we know what you are actually running. 我也不确定在我们知道您的实际运行之前,是否可以解决您的问题。 It could be a script. 可能是脚本。 There are several major problems with these installer projects . 这些安装程序项目存在几个主要问题

Custom Action : A Type 34 Custom Action allows you to Run an EXE file having a path referencing a directory . 自定义操作类型34自定义操作允许您Run an EXE file having a path referencing a directory You either need to hotfix your output MSI with Orca or use a real-deployment tool such as WiX or an equivalent commercial options . 您要么需要使用Orca来修复输出MSI,要么使用诸如WiX之类的实际部署工具或等效的商业选项 Though I have not tried, WiX should be capable of doing what you want - as should all the other, major commercial options. 尽管我没有尝试过,但是WiX应该能够完成您想要的事情-所有其他主要的商业选择也应该这样做。

Hotfixing : Hotfixing the MSI is somewhat involved meaning you have to add entries to the CustomAction Table and the InstallExecuteSequence Table . 修补程序 :MSI修补程序有些复杂,这意味着您必须向CustomAction TableInstallExecuteSequence Table添加条目。 You should not need to add the binary to the Binary Table if it is a file you want to run after it is installed or it is a file that exists on disk already. 如果二进制文件是要在安装后运行的文件,或者是磁盘上已经存在的文件,则无需将二进制文件添加到二进制表中 There are a number of flags you need to set for the custom action column Type which relates to whether the action runs synchronously or asynchronously, whether you want to abort on error or not, what sequence it will run in and that kind of stuff. 您需要为自定义操作列Type设置许多标志,这些标志与该操作是同步还是异步运行,是否要因错误而中止,它将以什么顺序运行以及类似的东西有关。 You combine bit fields. 您组合位字段。

You could pass a working directory into the program on the command line arguments, but only if the program is designed to take the value and use it as its working directory. 您可以在命令行参数上将工作目录传递到程序中,但前提是程序设计为采用该值并将其用作其工作目录。 Alternatively the program could just derive its running directory with code like this: 另外,程序也可以使用以下代码导出其运行目录:

> public static string GetAssemblyPathByCodeBase() {
>     string codeBase = Assembly.GetExecutingAssembly().CodeBase;
>     UriBuilder uri = new UriBuilder(codeBase);
>     return Path.GetDirectoryName(Uri.UnescapeDataString(uri.Path)); }

The general problem is that when the program is run from (say) a double click then the Explorer shell sets the working directory to be the hosting directory. 普遍的问题是,从(例如)双击运行程序时,Explorer Shell将工作目录设置为托管目录。 Windows Installer doesn't do that. Windows Installer不会这样做。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM