使用 WiX 创建现有文件夹的桌面快捷方式
我需要使用 Wix 创建现有文件夹(而不是文件)的桌面快捷方式。更详细地说,我的安装程序有一个使用 C# 编写的与其关联的 CustomAction 程序。此 CustomAction 程序创建一个名为“BSS”的文件夹,其路径由用户选择。
C:\ProgramData\MT\BSS
现在我需要使用 WiX 将桌面快捷方式放置到此文件夹。但是,我遇到了一个问题,因为该文件夹在 WiX 中没有文件夹结构。我能找到的最接近的代码如下。
<Directory Id="DesktopFolder" Name="Desktop"/>
<Directory Id="CommonAppDataFolder" Name="ProgramDataFolder"/>
<Component Id="ComponentBSStrageShortcut" Guid="{8436995c-2e76-4030-b92d-c6b4bc243c43}">
<Shortcut Id="ShortcutBSStrageShortcut"
Directory="DesktopFolder"
WorkingDirectory="APPLICATIONFOLDER"
Target="[CommonAppDataFolder]/MTK/BSStrage"
Name="BSStrage"
Show="normal"/>
<RegistryValue Action="write"
Key="SOFTWARE/MTK/BackStreet"
Root="HKCU"
Type="string"
KeyPath="yes"
Value="ApplicationFolderName"/>
</Component>
当我以这种方式构建安装程序时,它实际上在桌面上创建了一个快捷方式。然而,WiX 似乎认为 BSStrage 是一个文件/应用程序,因此它在位置 C:\ProgramData\MT 中放置了一个名为 BSStrage 的虚构应用程序的快捷方式。但是双击它没有帮助,因为没有可以用来打开它的程序。
显然我在这里做错了。有人可以帮我解决这个问题,以便如何克服这个问题。请注意,我对 Wix 非常陌生(才两天),以前从未使用过它。任何代码示例都会有很大帮助。
I have the need to create a Desktop Shortcut to an existing FOLDER (NOT to a file) using Wix. To elaborate more, my installer program has a CustomAction program written using C# associated with it. This CustomAction program creates a folder named "BSS" of which the path is selected by user.
C:\ProgramData\MT\BSS
Now I need to place a Desktop Shortcut to this folder using WiX. However, I encounter a problem since this folder does not have a folder structure within WiX. The closest code I could find was the following.
<Directory Id="DesktopFolder" Name="Desktop"/>
<Directory Id="CommonAppDataFolder" Name="ProgramDataFolder"/>
<Component Id="ComponentBSStrageShortcut" Guid="{8436995c-2e76-4030-b92d-c6b4bc243c43}">
<Shortcut Id="ShortcutBSStrageShortcut"
Directory="DesktopFolder"
WorkingDirectory="APPLICATIONFOLDER"
Target="[CommonAppDataFolder]/MTK/BSStrage"
Name="BSStrage"
Show="normal"/>
<RegistryValue Action="write"
Key="SOFTWARE/MTK/BackStreet"
Root="HKCU"
Type="string"
KeyPath="yes"
Value="ApplicationFolderName"/>
</Component>
When I build the installer this way, it actually creates a shortcut on Desktop. However, WiX seems to think that BSStrage is a file/application so it places a shortcut to an imaginary application called BSStrage in the location C:\ProgramData\MT. But double clicking on it dosen't help as there is no program that can be used to open it.
Obviously I'm doing it wrong here. Can someone please help me with this, so as how to overcome this problem. Note that I'm extremely new to Wix (it's been only two days) and has never worked with it before. Any code sample would be of great help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我刚刚遇到了同样的问题;似乎使用表单的
Target
属性创建Shortcut
标记Target="[CommonAppDataFolder]"
工作正常,但尝试附加子目录,例如Target="[CommonAppDataFolder]\MTK\BSStrage"
导致创建的快捷方式不起作用。幸运的是,我发现了一个解决方案。诀窍是创建一个
Directory
标记的层次结构,指向要创建快捷方式的目录,然后该目录包含一个Component
标记,其中包含Shortcut< /code> 标记,如下所示:
请注意,创建快捷方式时目标目录必须实际存在,否则您最终会遇到同样的问题:快捷方式损坏。这就是为什么我在
Component
标记内添加
标记,以在安装时创建目录。I just ran into the same problem; it seems that creating a
Shortcut
tag with aTarget
attribute of the formTarget="[CommonAppDataFolder]"
works fine, but trying to append subdirectories such asTarget="[CommonAppDataFolder]\MTK\BSStrage"
results in the creation of a shortcut that doesn't work.Fortunately, I've discovered a solution. The trick is to create a hierarchy of
Directory
tags leading to the directory that you want to create a shortcut to, which then contains aComponent
tag containing aShortcut
tag, like so:Note that the target directory has to actually exist at the time the shortcut is created, or else you'll end up with the same problem: a broken shortcut. This is why I added the
<CreateFolder/>
tag inside theComponent
tag, to create the directory on install.Shortcut/@Target 中的斜杠应该是反斜杠。资源管理器可能会将您的快捷方式解释为“使用开关 /MTK 和 /BSStrage 启动 CommonAppDataFolder”。至少,这是我的第一个猜测。
The slashes in your Shortcut/@Target should be backslashes. Explorer is probably interpreting your shortcut as "Launch CommonAppDataFolder with switches /MTK and /BSStrage". At least, that's my first guess.
我稍微改变了我的要求,并使代码按如下方式工作。改变的是现在我创建了 ProgramData 文件夹的快捷方式。
它工作正常并创建快捷方式。但是,存在一个问题,因为它在所有用户桌面上创建快捷方式,而我希望在当前用户的桌面上创建快捷方式。我应该做什么改变?
另请注意,我的安装程序执行所有用户安装,我无权更改它。我只需要一种在当前用户的桌面上创建此快捷方式的方法,而安装程序仍然可以进行所有用户安装。
I changed my requirements a bit and got the code to work as follows. Change being now I create a shortcut to the ProgramData folder.
It works fine and creates the shortcut fine. However there is one problem since it creates the shortcut on AllUsers Desktop while I want it to be created on the Current User's desktop. What change should I do?
Also note that my installer performs a all-user install, and I'm not at liberty to change that. I merely needs a way to create this shortcut on Current User's desktop while the installer can still do a all-user install.