我正在使用WixSharp来组装一个安装程序。我希望在Program Files\菜单中有一个打开网页的快捷方式。我能用WixSharp做到这一点吗?
发布于 2011-04-01 13:29:33
请查看可下载文件中的\Samples\Shortcuts。
发布于 2015-03-04 13:29:05
使用Internet注入功能将Wix#快捷方式的WiX代码放入您的构建中。对互联网快捷方式使用以下WiX语法示例:
<util:InternetShortcut Id="OnlineDocumentationShortcut"
Name="My Online Documentation"
Target="http://wixtoolset.org/"/>在您的Wix# installer代码中,首先,在您的主代码中,您将向"WixSourceGenerated“事件添加一个处理程序,该事件在.wxs文件创建之后、编译之前触发。该代码将如下所示:
// Hook up a delegate to the "WixSourceGenerated" event, fires when .wxs file is fully created
Compiler.WixSourceGenerated += InjectXMLElement;
// Make sure the .wxs file gets preserved
Compiler.PreserveTempFiles = true;
// Trigger the MSI file build
Compiler.BuildMsi(project);然后在你的委托方法中,你会有类似下面这样的代码:
/// <summary>
/// Insert XML elements and attributes into the generated .wxs file
/// </summary>
/// <param name="document"></param>
static void InjectXMLElement(System.Xml.Linq.XDocument document)
{
// To add an Internet shortcut on target system, add this element:
// <util:InternetShortcut Id="OnlineDocumentationShortcut"
// Name="My Online Documentation"
// Target="http://wixtoolset.org/"/>
var componentElement = document.Root.Select("Product/Directory/Directory/Component");
componentElement.Add(new XElement("util:InternetShortcut",
new XAttribute("Id", "OnlineDocumentationShortcut"),
new XAttribute("Target", "http://wixtoolset.org/")));
}您需要查看生成的.wxs文件,该文件与生成的MSI文件位于同一文件夹中,并找出"document.Root.Select()“的XPath是什么,才能找到要添加插入的WiX XML的节点。在我的wxs文件中,开始菜单快捷方式位于XML的一个部分,如下所示:
<Directory Id="ProgramMenuFolder" Name="ProgramMenuFolder">
<Directory Id="ProgramMenuFolder.My_App_Name" Name="My App Name">
<Component Id="My_App_Name.EmptyDirectory" Guid="18342da3-5a42-4397-b522-5927ace999">
<CreateFolder />
<RemoveFolder Id="ProgramMenuFolder.My_App_Name" On="uninstall" />
<RegistryKey Root="HKCU" Key="Software\WixSharp\Used">
<RegistryValue Value="0" Type="string" KeyPath="yes" />
</RegistryKey>
</Component>
</Directory> 因此,要在其中添加Internet快捷方式,您需要生成如下所示的XML:
<Directory Id="ProgramMenuFolder" Name="ProgramMenuFolder">
<Directory Id="ProgramMenuFolder.My_App_Name" Name="My App Name">
<Component Id="My_App_Name.EmptyDirectory" Guid="18342da3-5a42-4397-b522-5927ace999">
<CreateFolder />
<util:InternetShortcut Id="OnlineDocumentationShortcut"
Name="My Online Documentation"
Target="http://wixtoolset.org/"/>
<RemoveFolder Id="ProgramMenuFolder.My_App_Name" On="uninstall" />
<RegistryKey Root="HKCU" Key="Software\WixSharp\Used">
<RegistryValue Value="0" Type="string" KeyPath="yes" />
</RegistryKey>
</Component>
</Directory>我认为这并不像我所说的那样困难或复杂。要使XPath节点定位器指向正确的位置,只需要进行一些试验和错误。此外,我注意到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中的一个示例也演示了此技术。
发布于 2021-03-11 00:37:51
在WixSharp中,您可以通过InternetShortcut类创建一个InternetShortcut。
下面是我正在开发的一个应用程序的示例,它通过InternetShortcut类添加一个指向包含图标的网站的链接,并将该链接放在桌面和开始菜单上。
var project = new Project("MyApplicationName", // Installer name
new Dir(@"%ProgramFiles%\MyApplicationName", // Install directory
new Files(@"..\MyApplicationName\bin\Release\netcoreapp3.1\publish\*.*")), // Source directory
new Dir(@"%ProgramMenu%\MyApplicationName",
new InternetShortcut
{
Name = $"Admin Page",
Target = "http://localhost:4444",
Type = InternetShortcut.ShortcutType.link,
AttributesDefinition = @"IconFile=[INSTALLDIR]\icon.ico;IconIndex=0"
},
new ExeFileShortcut
{
Name = "Uninstall",
Target = "[System64Folder]msiexec.exe",
Arguments = "/x [ProductCode]"
}),
new Dir(@"%Desktop%",
new InternetShortcut
{
Name = $"Admin Page",
Target = "http://localhost:4444",
Type = InternetShortcut.ShortcutType.link,
AttributesDefinition = @"IconFile=[INSTALLDIR]\icon.ico;IconIndex=0"
})
); 另请参阅:
https://stackoverflow.com/questions/5287711
复制相似问题