创建自定义操作来启动应用程序并退出安装程序
感谢 StackOverflow,我昨天发现了如何向 Visual Studio 安装程序添加自定义操作以在更新后启动我的程序。我现在面临的问题是,在安装程序结束时,程序确实打开,但安装程序永远不会完成,直到我退出我的应用程序。
有没有办法确保应用程序仅在用户单击 MSI 包上的“完成”后启动? 或者程序在安装程序完成时启动,但安装程序完成并退出?
我正在运行 Visual Studio 2010,以防万一。
Thanks to StackOverflow I found out yesterday how to add a custom action to the Visual Studio Installer to start my program after an update. The problem I now face is that at the end of the installer the program does open but the installer never finishes until I exit my app.
Is there a way to ensure the app starts only after the user clicks finish on the MSI package?
Or the program starts at finish of installer but installer completes and exits?
I am running Visual Studio 2010 in case it matters.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
经过一番谷歌搜索后,我发现 Visual Studio 安装程序的自定义操作可能需要指向安装程序类。所以我在我的解决方案中创建了一个类型为 class 的新项目。我删除了 class1.cs 文件,并使用以下代码向新项目添加了一个安装程序类(注意:在某些时候需要使用 security.permissions):
添加 InstallerClass 后,我右键单击安装程序项目并选择添加>项目输出并添加了安装程序类。然后我右键单击已安装的项目并执行“查看”>“自定义操作。我将安装程序类添加到 Install 和 Commit 文件夹中(如果只将其添加到 Commit 中,则会收到错误 1001:找不到文件 InstallState。由于覆盖提交,它只会在提交时运行。显然 InstallState 是在第 2 阶段创建,因此如果两者都不存在,它将惨败)。
您必须添加 CustomActionData 条目。为此,请选择“来自 InstallerClass 的主输出”并转到“属性”选项卡。将以下内容粘贴到 CustomActionData 中:
添加后,应用程序在安装完成时正常运行,您可以关闭安装程序,而不必等待应用程序退出!
正是我所需要的。感谢谷歌拯救了我的培根。
我注意到的一个问题是安装程序现在在我的 ApplicationFolder 中创建多个 .tmp 文件和一个 .InstallState 文件。我想知道是否需要在安装程序类中添加一些额外的内容来删除这些无用的文件?
弄清楚如何删除临时文件。使用 Dispose() 更新了代码。
After some Googling, I found out that the custom action for the Visual Studio Installer might need to point to an Installer Class. So I created a new project of type class in my solution. I deleted the class1.cs file and added an installer class to the new project with the following code (mental note: need to use security.permissions at some point):
After the InstallerClass was added, I right clicked on the installer project and selected Add > Project Output and added the installer class. I then right clicked on the installed project and did View > Custom Action. I added the installer class to both the Install and Commit folders (if you only add it to Commit, you will get an Error 1001: could not find file InstallState. because of the override commit, it will only run on commit. apparently InstallState is created at stage 2 so if if its not in both it will fail miserably).
You must add a CustomActionData entry. To do so, select the "Primary Output from InstallerClass" and go to the Properites tab. Paste the following in CustomActionData:
After that was added the app runs properly when the install finishes and you can close the installer instead of waiting on the app to exit!
Just what I needed. Thank you Google for saving my bacon.
The one issue I noticed was the installer now creates multiple .tmp files and a .InstallState file in my ApplicationFolder. I am wondering if there is something in addition that needs to be added to the installer class to get rid of these useless files?
Figured out how to get rid of the temp files. Updated code with Dispose().
我按照这里的说明进行操作:
http://msdn.microsoft.com/en-us/library/d9k65z2d.aspx
..并收到“错误 1001:找不到文件 InstallState”错误。
读完上面 ThaKidd 的回答后,我意识到我必须:
将安装程序类添加到 Install 和 Commit 文件夹中。
非常重要。只是将其留在这里供未来的访客使用(如果允许的话,我会添加评论......)
I followed the instructions here:
http://msdn.microsoft.com/en-us/library/d9k65z2d.aspx
..And got the "Error 1001: could not find file InstallState" error.
After reading ThaKidd's answer above, I realized that I would have to:
Add the installer class to both the Install and Commit folders.
Really important. Just leaving this here for future visitors (I would have added a comment if SO allowed me to...)
这是回答问题并清理卸载事件中的所有文件的分步指南。我希望这可以帮助刚接触 Visual Studio 安装程序项目的人。
在您的解决方案 (.sln) 中,您应该至少有 2 个项目。一个是您的程序,另一个是设置。鉴于该问题,本指南不包括有关如何添加设置或主要输出的基础知识(如果您需要了解,请观看视频)。
请按照下列步骤操作:
完整代码
Visual Studio 安装程序项目(2017、2019)的其他内容可能会在以后为您省去麻烦:
This is a step by step guide to answer the Question and clean up all files on an uninstall Event. I hope this can help people who are new to Visual Studio Installer Projects.
In your solution (.sln) you should have at least 2 projects. One being your program and the other one the setup. Given the Question this guide does not include basics on how to add a setup or the primary output(Here is a video if you need to catch up).
Follow these steps:
Full Code
Additional stuff for a Visual Studio Installer Projects (2017, 2019) that might save you a headache later: