将环境变量获取到 WiX 属性中

发布于 2024-09-14 02:14:44 字数 248 浏览 6 评论 0 原文

有没有办法将环境变量放入 WiX 属性中?

我试图通过以下方式获取 USERPROFILE:

Property Id="UserFolder"  Value="$(env.USERPROFILE)\EdwardsApp\MyFolder"

但这只会获取构建安装程序的构建计算机的 USERPROFILE。

我希望它使用安装应用程序的计算机的USERPROFILE

Is there a way to get an environment variable into a WiX property?

I'm trying to get the USERPROFILE with:

Property Id="UserFolder"  Value="$(env.USERPROFILE)\EdwardsApp\MyFolder"

But this only picks up the USERPROFILE of the build machine where the installer is built.

I want it to use the USERPROFILE of the machine where the app is being installed.

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

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

发布评论

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

评论(4

翻身的咸鱼 2024-09-21 02:14:44

另一种方法是使用 SetProperty 元素 - 它将有效创建类型 51 自定义操作。它比使用自定义操作更简单,因为您不需要单独指定它的计划 - 一切都在一个元素中完成。在下面的示例中,仅当属性为空时(即不是从命令行传递的),我才设置该属性。

例子:

<SetProperty Id="PROP_MYSOME"
             Before="InstallInitialize" 
             Sequence="execute"
             Value="[%USERDOMAIN]">
    <![CDATA[NOT Installed AND PROP_MYSOME=""]]>
</SetProperty>

Alternative is to use SetProperty element - it will effectively create type 51 custom Action. It is simpler than using Custom Action as you don't need to separately specify the schedule for it - everything is done in one element. In my example below, I set the property only if its empty, i.e. was not passed from the command line.

Example:

<SetProperty Id="PROP_MYSOME"
             Before="InstallInitialize" 
             Sequence="execute"
             Value="[%USERDOMAIN]">
    <![CDATA[NOT Installed AND PROP_MYSOME=""]]>
</SetProperty>
哭泣的笑容 2024-09-21 02:14:44

您可以在安装过程中使用环境变量,但这需要使用自定义操作。您需要使用 UserFolder 属性rel="noreferrer">键入 51 自定义操作,而不是在构建期间设置属性。 [%ENVVARNAME] 格式用于使用环境变量,但环境变量的名称区分大小写。

设置属性的自定义操作的 WiX 示例:

<CustomAction Id="SetUserFolder" Property="UserFolder" Value="[%USERPROFILE]EdwardsApp\MyFolder" />

您可以在此处阅读有关 WiX 中自定义操作的更多信息:

http://blogs.technet.com/b/alexshev/archive/2008/02/21/from-msi- to-wix-part-5-custom-actions.aspx

You can make use of Environment variables during installation but this requires using a custom action. You will need to set the UserFolder property with a Type 51 Custom Action as opposed to setting the property during the build. The [%ENVVARNAME] format is used to make use of an environment variable, but the name of the environment variable is case-sensitive.

A WiX example of a custom action that sets a property:

<CustomAction Id="SetUserFolder" Property="UserFolder" Value="[%USERPROFILE]EdwardsApp\MyFolder" />

You can read more on Custom Actions in WiX here:

http://blogs.technet.com/b/alexshev/archive/2008/02/21/from-msi-to-wix-part-5-custom-actions.aspx

俏︾媚 2024-09-21 02:14:44

由于我还无法添加评论,因此对于 @demp 的回答,我必须这样做才能在初始化期间的某个时间评估条件,以便该值可以显示在 UI 对话框中:

<SetProperty Id="MY_PROPERTY"
             Value="[%USERDOMAIN]" 
             After="LaunchConditions"
             Sequence="first"  />

相信 Before="InstallInitialize" 发生在安装本身继续进行之前(即复制文件等),而不会发生在安装程序本身的初始化阶段。

Since I can't add a comment yet, with regard to @demp's answer, I had to do this to get the condition to evaluate sometime during initialization so that the value could be displayed in a UI dialog:

<SetProperty Id="MY_PROPERTY"
             Value="[%USERDOMAIN]" 
             After="LaunchConditions"
             Sequence="first"  />

I believe that Before="InstallInitialize" happens just before the installation itself proceeds (i.e. copying files and whatnot) and not during the initialization phase of the installer itself.

绝對不後悔。 2024-09-21 02:14:44

就我而言,我希望获取目标计算机的 USERPROFILE 环境变量来安装那里的所有文件。我实现了这样的目标:

<Property Id="HOME_FOLDER" >
  <DirectorySearch Id="userProfileSearch" Depth="0" Path="[%USERPROFILE]" />
</Property>

然后所有文件都到达我想要的位置。

In my case, I'm looking to get the USERPROFILE environment variable of the target machine to install all the files there. I achieved that like:

<Property Id="HOME_FOLDER" >
  <DirectorySearch Id="userProfileSearch" Depth="0" Path="[%USERPROFILE]" />
</Property>

Then all the files went where i wanted them to go.

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