如何使用 WixSharp 创建互联网快捷方式
我正在使用 WixSharp 来组合安装程序。我希望在 Program Files\ 菜单中有一个快捷方式来打开网页。我可以用 WixSharp 做到这一点吗?
I'm using WixSharp to put together an installer. I'd like to have a shortcut in the Program Files\ menu to open a webpage. Can I do that with WixSharp?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在 WixSharp 中,您可以通过 InternetShortcut 类。
下面是我正在开发的一个应用程序的示例,该应用程序通过 InternetShortcut 类添加指向包含图标的网站的链接,并将该链接放置在桌面和开始菜单上。
另请参阅:
In WixSharp you can create an InternetShortcut via the InternetShortcut class.
Below is an example from an app I'm working on of adding a link to a website that includes an icon via the
InternetShortcut
class and placing that link on both the Desktop and Start Menu.See also:
使用 Wix# XML 注入功能将 Internet 快捷方式的 WiX 代码放入您的构建中。使用此 WiX 语法示例作为 Internet 快捷方式:
在 Wix# 安装程序代码中,首先在主代码中,您将向“WixSourceGenerate”事件添加一个处理程序,该事件在创建 .wxs 文件之后但之前触发已编译。该代码将如下所示:
然后在您的委托方法中,您将拥有如下所示的代码:
您将需要查看生成的 .wxs 文件,该文件将与生成的 MSI 文件位于同一文件夹中,然后图找出 XPath 是什么,以便“document.Root.Select()”到达要添加插入的 WiX XML 的节点。在我的 wxs 文件中,“开始”菜单快捷方式位于 XML 的一部分,如下所示:
因此,要在其中添加 Internet 快捷方式,您会希望生成的 XML 看起来像这样:
我认为这并不困难或也许正如我所表现的那样,参与其中。只需进行一些尝试和错误即可将 XPath 节点定位器指向插入 XML 的正确位置。另外,我注意到 Wix# XML 语法似乎与 WiX 略有不同(并且在这个“快捷方式”区域不太完整)。 (例如,Wix# 插入了 WiX 没有的元素,并且 WiX 允许您更清楚地指定快捷方式的开始文件夹和其他值)我使用的示例 XML 来自我拥有的添加“开始”菜单的 Wix# 安装程序快捷方式。如果您想对快捷方式采用更纯粹的 WiX 方法,并使用此方法将它们全部注入,请参考以下 WiX 链接:
http://wixtoolset.org/documentation/manual/v3/howtos/files_and_registry /create_start_menu_shortcut.html
http://wixtoolset.org/documentation /manual/v3/howtos/files_and_registry/create_internet_shortcut.html
用于快捷方式的纯 WiX XML 注入方法的优点是允许您对创建的内容有更多的控制。
在 Wix# 示例中,Samples\InjectXML\Setup.cs 中有一个示例也展示了此技术。
Use the Wix# XML injection feature to place the WiX code for an Internet shortcut into your build. Using this WiX syntax example for an Internet shortcut:
In your Wix# installer code, first, in your main code, you would add a handler to the "WixSourceGenerated" event, which fires after the .wxs file has been created, but before it is compiled. That code would look like this:
Then in your delegate method, you would have code that looks something like this:
You will need to look in your generated .wxs file, which will be in the same folder as your generated MSI file, and figure out what the XPath is, for "document.Root.Select()" to get to the node where you want to add the inserted WiX XML. In my wxs file, the Start Menu shortcuts are in a section of the XML that looks like this:
So to add an Internet shortcut there, you would want the resulting XML to look something like this:
I don't think it's as difficult or involved as I perhaps made it look. It will just take a little trial and error to get the XPath node locator pointed to the right place to insert your XML. Also, I notice that Wix# XML syntax seems to be a little different (and less complete in this "shortcuts" area) than WiX. (For example, Wix# inserts a element that WiX doesn't, and WiX allows you to specify the start folder and other values for the shortcut more clearly) The example XML I used comes from a Wix# installer I have that adds Start Menu shortcuts. If you want to do a more pure WiX approach for shortcuts, and just inject them all, using this approach, then refer to these WiX links:
http://wixtoolset.org/documentation/manual/v3/howtos/files_and_registry/create_start_menu_shortcut.html
http://wixtoolset.org/documentation/manual/v3/howtos/files_and_registry/create_internet_shortcut.html
The pure WiX XML injection approach for shortcuts would have the advantage of allowing you a bit more control over what gets created.
In the Wix# samples, there is a sample in Samples\InjectXML\Setup.cs that also shows this technique.
查看可下载内容中的\Samples\Shortcuts。
Have a look at <Wix#>\Samples\Shortcuts in the downloadables.