问题描述
经过几天的点击和试用,我为一个简单的解决方案创建了 WIX 安装程序,并遵循了几个教程,以便包括在安装结束时启动应用程序的选项、桌面上和添加/删除程序中带有图标的应用程序快捷方式列表.当它运行良好时,我为包含 6 个项目和 SQLite 数据库的原始项目复制了相同的过程.但是现在当我安装安装程序时,单击桌面上已安装的图标无效.它不会启动指定的 exe.请帮助我.
I created WIX installer for a simple solution after several days of hit and trial, and following several tutorials in order to include the options of launching app at the end of installation, app shortcuts with icons on desktop and in Add/Remove Programs list. When it worked fully well, I replicated the same process for my original project that contains 6 projects and SQLite db. But now when i install the installer, clicking on the installed icon on Desktop has no effect. It doesn't launch the designated exe. Kindly help me.
我应该分享 wxs 代码吗?
Should i share the wxs code?
更新:以下是我的 .wxs 文件的大部分代码.抱歉,我无法破译问题的根源,因此必须包含除标准顶部标签之外的所有代码.此外,一旦发现问题,它可以为其他 Wix 用户提供参考.
Update: Following is most of the code of my .wxs file. Sorry I could not decipher the source of problem so had to include all the code except the standard top tags. Moreover, it could be a reference for other Wix users to benefit from, once the problem is identified.
<!-- Embed cab1 file inside the package -->
<Media Id="1" Cabinet="cab1.cab" EmbedCab="yes" />
<!-- Specify Installation folders -->
<Directory Id="TARGETDIR" Name="SourceDir">
<!-- Program Files folder i.e. on HDD -->
<Directory Id="ProgramFilesFolder">
<Directory Id="INSTALLFOLDER" Name="Pihu" />
</Directory>
<!-- Program Menu folder i.e. on Start Menu -->
<Directory Id="ProgramMenuFolder">
<Directory Id="ProgramMenuDir" Name="Pihu Co." />
</Directory>
<!-- Desktop folder-->
<Directory Id="DesktopFolder"/>
</Directory>
<!-- Add Main App's exe-->
<DirectoryRef Id="INSTALLFOLDER">
<Component Id="Pihu.exe" Guid="*">
<File Id="PihuEXE" Source="../Pihu/bin/$(var.BUILD)/Pihu.exe"
Name="Pihu.exe" KeyPath="yes"/>
</Component>
</DirectoryRef>
<!-- Icon for Add/Remove Program must be specified separately by following 2 lines -->
<Icon Id="AddRemoveProgIcon" SourceFile="Pihu.ico"/>
<Property Id="ARPPRODUCTICON" Value="AddRemoveProgIcon" />
<!-- Add shortcut for Start Menu-->
<DirectoryRef Id="ProgramMenuDir">
<Component Id="StartMenuShortcut" Guid="*">
<Shortcut Id="StartMenuShortcut" Name="Pihu HMI" Description="Pihu HMI"
Target="[INSTALLFOLDER]Pihu.exe" WorkingDirectory="INSTALLFOLDER">
<!--Add Icon to the ShortCut-->
<Icon Id="StartMenuIcon" SourceFile="Pihu.ico"/>
</Shortcut>
<RegistryValue Root="HKCU" Key='Software\[Manufacturer]\[ProductName]'
Name="installed" Type="string" Value="[INSTALLFOLDER]" KeyPath="yes"/>
<!--Remove the StartMenu folder at Uninstall time -->
<RemoveFolder Id="StartMenuShortcut" On="uninstall"/>
</Component>
</DirectoryRef>
<!-- Add shortcut for DeskTop-->
<DirectoryRef Id="DesktopFolder">
<Component Id="DesktopShortcut" Guid="*">
<Shortcut Id="DesktopShortcut" Name="Pihu HMI" Description="Pihu HMI"
Target="[INSTALLFOLDER]Pihu.exe" WorkingDirectory="INSTALLFOLDER">
<Icon Id="DeskTopIcon" SourceFile="Pihu.ico"/>
</Shortcut>
<RegistryValue Root="HKCU" Key='Software\[Manufacturer]\[ProductName]'
Name="installed" Type="string" Value="[INSTALLFOLDER]" KeyPath="yes"/>
<RemoveFolder Id="DesktopFolder" On="uninstall"/>
</Component>
</DirectoryRef>
<WixVariable Id="WixUILicenseRtf" Value="License.rtf"/>
<!-- Add Component -->
<Feature Id="MainApplication" Title="Pihu HMI" Level="1" ConfigurableDirectory="INSTALLFOLDER">
<ComponentRef Id="Pihu.exe" />
<!-- Add feature for Start menu shortcut-->
<ComponentRef Id="StartMenuShortcut" />
<!-- Add feature for DeskTop shortcut-->
<ComponentRef Id="DesktopShortcut" />
</Feature>
<Property Id="WIXUI_EXITDIALOGOPTIONALCHECKBOXTEXT" Value="Launch Pihu HMI Application now" />
<Property Id="WixShellExecTarget" Value="[#PihuEXE]" />
<CustomAction Id="LaunchApplication" BinaryKey="WixCA" DllEntry="WixShellExec" Impersonate="yes" />
<UI>
<UIRef Id="WixUI_FeatureTree"/>
<Publish Dialog="ExitDialog" Control="Finish" Event="DoAction" Value="LaunchApplication">
WIXUI_EXITDIALOGOPTIONALCHECKBOX = 1 and NOT Installed
</Publish>
</UI>
Pihu.exe 从 Debug 或 Release 文件夹运行时运行良好.第一个屏幕独立于数据库,因此不会有问题.我认为唯一的问题是解决方案是多项目(尽管所有依赖项目的 dll 也存在于 Debug 和 Release 文件夹中)
Pihu.exe runs fine when run from the Debug or Release folder. First screen is independent of the DB so that cannot be a problem. I think the only problem is the solution being multi-project (although dlls of all the dependent projects are also present in Debug as well as Release folders)
推荐答案
一旦您向问题添加更多详细信息,我将演变"这个答案.我想避免太多评论.是的,请在您的问题中分享您的 WiX 源代码的核心,或者甚至是已编译的 MSI 本身,如果它是公开的且不是太大,并且您有上传它的地方 - 链接到它.
I will "evolve" this answer once you add more details to your question. I want to avoid too many comments. And yes, please share the core of your WiX source in your question, or even the compiled MSI itself if it is public and not too large and you got a place to upload it - link to it.
请在发布前从您的 WiX 源中删除任何密码、数据库连接字符串、用户名、共享名称、IP 地址或其他敏感数据.一个好的包不应该硬编码任何这些(它们应该是最终用户在安装时设置的参数),但正如我们所知,有时硬编码的东西(通常来自你的开发箱)在安装过程中潜入源代码发展 - 给它一次.还请消除源代码中的硬编码 GUID - 将它们替换为 PUT-GUID-HERE(不是那么重要,如果您不确定如何操作,我们会帮助您做到这一点).
Please eliminate any passwords, database connection strings, user names, share names, IP-addresses, or other sensitive data from your WiX source before posting. A good package shouldn't hard-code any of this (they should be parameters set by the end user at install time), but as we know, sometimes hard-coded stuff (often from your dev-box) sneaks into the source during development - give it a once-over. Please also eliminate hard coded-GUIDs in the source - replace them with PUT-GUID-HERE (not that critical, we will help you do that if you are unsure how).
- 您是否在新项目中为产品代码、包代码、组件 GUID 等使用了新的 GUID?如果您重复使用封装代码或组件代码,可能会出现非常奇怪的结果.重复使用相同的产品代码更容易被发现,但这也会导致问题.
- 您是否尝试过直接从文件系统启动主 EXE?(检查问题是否出在快捷方式上).
- 在您尝试启动应用程序时是否有任何错误消息?您是否也检查了事件日志(除了任何 GUI 错误)?应用程序是否具有自己的自定义日志记录?如果是这样,请检查.
- 您是否在安装后扫描二进制文件中的依赖项?只需提供我最近写的答案的链接:在 Visual Studio 2017 中为 WPF 应用程序创建 MSI 安装程序后,EXE 什么也不做(Dependencies.exe、procmon.exe、visual studio 模块视图、几个选项...).您也可以尝试使用旧的 Dependency Walker 即使它现在很旧并且不能很好地处理 Win32 程序集依赖项或 Api 集.
- 您是否记录了 MSI 安装?如果没有,请这样做并检查是否有任何错误.有关如何记录 MSI 安装的信息,请参阅以下部分.
- 拥有日志后,您可以在日志文件中搜索value 3",如 Rob Mensching 此处所述,但在您的情况下,安装似乎已成功完成,因此您需要查找警告并抑制错误.
- 强烈推荐这篇来自 Windows Installer 团队的 Robert Macdonald 的文章作为对 MSI 日志记录的实用介绍:如何解释 Windows 安装程序日志.
- 全系列msiexec.exe 命令行选项.这是技术网版本.
- Did you use new GUIDs for product code, package code, component GUIDs etc... for your new project? Really strange results can occur if you re-use a package code or component codes. Reusing the same product code is easier to detect, but that can also cause problems.
- Did you try launching the main EXE directly from the file system? (to check if the problem is with the shortcut).
- Are there any error messages when you try to launch the application? Did you check the event logs as well (in addition to any GUI errors)? Does the application feature its own custom logging? If so, please check.
- Did you scan the binary for dependencies after installation? Just throwing in a link to a recent answer I wrote: After creating MSI Installer for WPF app in Visual Studio 2017, EXE does nothing (Dependencies.exe, procmon.exe, visual studio modules view, several options...). You can also try the old Dependency Walker even if it is old now and doesn't deal well with Win32 assembly dependencies or Api-Sets.
- Did you log the MSI installation? If not, please do so and check for any errors. See section below for how to log an MSI installation.
- Once you have a log, you can search for "value 3" in the log file as explained by Rob Mensching here, but in your case the install seems to have completed successfully, so you need to look for warnings and suppressed errors as well.
- This article from Robert Macdonald from the Windows Installer Team is highly recommended as a practical look at MSI logging: How to Interpret Windows Installer Logs.
- The full range of msiexec.exe command line options. Here is the technet version.
以下是记录安装的方法:
Here is how to log your install:
msiexec.exe /I "C:\Installer.msi" /QN /L*V "C:\msilog.log"
快速参数说明:
/I = run regular installation sequence /QN = run completely silently /L*V "C:\My.log" = verbose logging at specified path
如果这令人困惑尝试 installsite.org 的日志常见问题解答 - 如何为您的安装创建日志文件.
If this is confusing try installsite.org's logging FAQ - how to create a log file for your installation.
Wix 没有自动魔术"功能 - 开箱即用 - 从某种意义上说,所有相关文件都会在构建时自动包含(除非有我不知道的新功能).
Wix does not feature "automagic" - out of the box - in the sense that all dependent files are automatically included at build time (unless there is a new feature I am not aware of).
您必须手动指定要与 MSI 一起安装的文件,坦率地说,这是我认为的预期行为 - WiX 为您提供的是安装程序的控制权和灵活性 - 代价是处理起来有些繁琐有时.但是,如果您尽可能轻松地做到这一点,您就会为您的 MSI 的 WiX 源的灵活性和清晰度感到高兴.
You have to manually specify what files are to be installed with your MSI, and frankly this is expected behavior in my opinion - what WiX gives you is control and flexibility of your installer - at the cost of being somewhat fiddly to deal with at times. However, if you do it as easy as possible you will appreciate the flexibility and clarity of a WiX source for your MSI.
那么,您如何尽可能简单地处理这个问题?我只是在 Visual Studio 中将您的构建类型设置为发布",然后转到
Debug =>开始调试
以交互方式运行您的项目.现在转到Debug =>窗户 =>Modules
并记下所有加载的文件(模块).然后将您的解决方案加载的文件包含在您的 WiX 源中以部署到目标系统,并识别从机器上其他地方(例如 GAC)加载的共享文件(系统文件)并确定它们是否需要安装运行时系统上.您不得将此类共享(或系统)文件直接包含在您的 WiX 源中,而是通过合并模块(一种用于安装共享运行时的机制)或单独的 setup.exe 来完成安装运行时的工作.So, how do you deal with this as simple as possible? I would just set your build type to "Release" in Visual Studio, and then go
Debug => Start Debugging
to run your project interactively. Now go toDebug => Windows => Modules
and make a note of all the files (modules) that are loaded. Then include the files loaded by your solution in your WiX source for deployment to the target system, and identify shared files (system files) that are loaded from elsewhere on the machine (GAC for example) and determine if they require a runtime to be installed on the system. You must not include such shared (or system) files directly in your WiX source, but via a merge module (a mechanism for installing shared runtimes) or a separate setup.exe that does the job of installing the runtime.为了将这些文件包含在您的 WiX 源中,您只需将它们添加到 WiX 源中的相应目录中.最简单的形式:
In order to include these files in your WiX source, you simply add them to the appropriate directory in your WiX source. In its simplest form:
<Component> <File Source="C:\Users\Acer\SourceControl\MyProject\CoreApp.exe" /> </Component>
上述组件包含单个文件,该元素利用了 WiX 的能力,根据文件名本身默认大多数属性.组件 ID 和 GUID 是自动生成的 - 文件 ID 和名称也是如此.我之前在这个答案中简要地写过这个 - 也许有一个快速浏览:WIX 中的 guid 语法?.
The above component contains a single file, and the element takes advantage of WiX's ability to default most attributes based on the file name itself. The Component Id and GUID is auto-generated - as is the File Id and Name as well. I wrote briefly about this before in this answer - maybe have a quick skim: Syntax for guids in WIX?.
在您的源代码中内嵌,添加文件将如下所示(使用上面链接答案中描述的这些最小组件元素):
Inline in your source, adding a file would look something like this (using these minimal component elements as described in the linked answer directly above):
<DirectoryRef Id="INSTALLFOLDER"> <Component Id="Pihu.exe" Guid="*"> <File Id="PihuEXE" Source="../Pihu/bin/$(var.BUILD)/Pihu.exe" Name="Pihu.exe" KeyPath="yes"/> </Component> <Component> <File Source="C:\Users\Acer\SourceControl\MyProject\CoreApp.exe" /> </Component> <Component> <File Source="C:\Users\Acer\SourceControl\MyProject\CoreApp.dll" /> </Component> <Component> <File Source="C:\Users\Acer\SourceControl\MyProject\CoreApp2.dll" /> </Component> </DirectoryRef>
这只是我能想到的最简单的模型.source 属性是您需要指定的唯一必需属性.我已将其设置为绝对路径以确保文件编译,但您应该使用 WiX 项目变量,就像您在上面的源代码中所做的那样.请参阅使用项目引用和变量.当您在使用它时,您还应该快速浏览一下预处理器功能一>.
That's just the simplest mock-up I can think of. The source attribute is the only mandatory one you need to specify. I have set it to an absolute path to ensure the file compiles, but you should make use of WiX project variables, as you do in your source above. See Using Project References and Variables. While you are at it you should also have a quick look at the Preprocessor features.
如果您正确地按照项目引用和变量的说明进行操作,您应该能够获得看起来像这样的源代码(但在深入研究之前,也许可以使用绝对路径编译 WiX 源代码 - 请注意
ConsoleApplication
显然是编译应用程序二进制文件的 Visual Studio 项目的名称):If you follow the instructions properly for the project references and variables, you should be able to get a source that look something like this (but maybe get the WiX source to compile with absolute paths before you delve into this - note that
ConsoleApplication
is obviously the name of your Visual Studio project that compiles your application binaries):<DirectoryRef Id="INSTALLFOLDER"> <Component Id="Pihu.exe" Guid="*"> <File Id="PihuEXE" Source="../Pihu/bin/$(var.BUILD)/Pihu.exe" Name="Pihu.exe" KeyPath="yes"/> </Component> <Component> <File Source="$(var.ConsoleApplication.TargetDir)\SupportFile1.dll" /> </Component> <Component> <File Source="$(var.ConsoleApplication.TargetDir)\SupportFile2.dll" /> </Component> <Component> <File Source="$(var.ConsoleApplication.TargetDir)\SupportFile3.dll" /> </Component> </DirectoryRef>
请试一试.我现在没有时间测试编译这个,我自己使用不同的方案(我使用预处理器和
<? 语句来指定我复制的发布文件夹所有输出文件 - 我不直接从 Visual Studio 输出文件夹中引用文件).
Please give this a go. I don't have time to test compile this right now, and I use a different scheme myself (I use the preprocessor and
<? statements to specify a release folder where I have copied all output files - I don't reference files directly from the Visual Studio output folders).
看起来您已经在使用 BUILD 变量执行此操作,但我通常使用基本构建输出路径,例如:
It does look like you are already doing this with your BUILD variable, but I generally use a base build output path such as this:
然后我的源元素变成这样:
and then my source elements become something like this:
<Component> <File Source="$(var.RELEASEFOLDER)\MyApp.exe" /> </Component>
比我认为的要多得多的细节和可能的意见,但我希望它可以帮助您解决问题.一旦设置好 WiX 源,就可以在需要时进行调整.灵活性出众.
A lot more detail and probably opinions than you need I think, but I hope it helps you solve your problem. Once set up WiX sources are fantastic to tweak when you need it. The flexibility is outstanding.
如果你只是要添加几个文件,上面的方法应该没问题.但是,如果您要添加大量文件,则应使用 WiX 工具
heat.exe
.它允许您收获"目录并生成带有所需组件和文件元素的 WiX XML,以安装有问题的文件.这里是heat.exe的官方文档一>.If you just have a few files to add, the above method should be fine. However, if you have lots of files to add you should use the WiX tool
heat.exe
. It allows you to "harvest" directories and generate WiX XML with the required component and file elements to install the files in question. Here is the official documentation for heat.exe.以最简单的形式,您可以使用以下内容:
In its simplest form you could use something like this:
- 打开命令提示符并导航到要包含在 MSI 中的文件夹结构.
- 试试像
heat.exe dir 这样的东西.-sfrag -out HeatTest.wxs
生成 WiX XML 文件HeatTest.wxs
.它现在将包含从您导航到的文件夹及下方(.
表示当前文件夹)安装相关文件所需的 XML. - 我更喜欢搜索
Guid="PUT-GUID-HERE"
并将其替换为空字符串,因为 GUID 可以自动生成.我没有看到允许创建最小 WiX XML"的开关——换句话说,只有必需的属性.我认为您也可以省略目录 ID. - 我还喜欢用定义的值(例如 RELEASEFOLDER)替换源属性默认路径.像这样:
heat.exe dir .-sfrag -var var.RELEASEFOLDER -out HeatTest.wxs
.试试看.现在 Source 属性变成了这样:Source="$(var.RELEASEFOLDER)\src\Burn\Frost\Frost.sln"
而不是Source="SourceDir\src\Burn\Frost\Frost.sln"
.
- Open a command prompt and navigate to the folder structure you want to include in your MSI.
- Try something like
heat.exe dir . -sfrag -out HeatTest.wxs
to generate the WiX XML fileHeatTest.wxs
. It will now contain the required XML to install the files in question from the folder you navigated to and below (.
means current folder). - I prefer to search for and replace
Guid="PUT-GUID-HERE"
with an empty string since the GUID can be auto-generated. I don't see a switch to allow the creation of "Minimal WiX XML" - in other words with only required attributes. I think you can leave out the Directory Ids as well. - I also like to replace the source attribute default path with a heat.exe dir . -sfrag -var var.RELEASEFOLDER -out HeatTest.wxs. Try it out. Now the Source attribute becomes something like:
Source="$(var.RELEASEFOLDER)\src\Burn\Frost\Frost.sln"
instead ofSource="SourceDir\src\Burn\Frost\Frost.sln"
.
通过一些练习,使用这个 heat.exe 工具为您的 MSI 创建基本安装结构变得非常快速,并对生成的源进行一些手动清理.我非常喜欢它创建乏味的文件密集型"程序包,例如 IIS 安装程序,这些程序包可能包含数千个文件,手动创建 WiX XML 是无望的.
With some practice it becomes really quick to create the basic install structure for your MSI using this heat.exe tool with some manual cleanup of the generated source. I like it a lot for creating tedious "file intensive" packages such as IIS installers that may contain thousands of files that would be hopeless to try to create WiX XML for manually.
这篇关于C# 应用程序(使用 WIX 创建的安装程序)在安装后不运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!