.net 在 Visual Studio 安装项目中安装后如何启动应用程序
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/247446/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I launch an application after install in a Visual Studio Setup Project
提问by adeel825
I have created a setup project using Visual Studio 2008. After the application is finished installing, I would like to have it start up immediately. Any thoughts on how this can be done?
我使用 Visual Studio 2008 创建了一个安装项目。应用程序安装完成后,我希望它立即启动。关于如何做到这一点的任何想法?
采纳答案by Gulzar Nazim
回答by Peter Kelly
I've used a script to place a checkbox "Launch [ProductName]" on the final form of the MSI. I cannot take any credit for the script though. You can find the script over on Aaron Stebner's blog at MSDN http://blogs.msdn.com/astebner/archive/2006/08/12/696833.aspx
我使用脚本在 MSI 的最终形式上放置了一个复选框“Launch [ProductName]”。不过,我不能对剧本有任何功劳。您可以在 Aaron Stebner 的 MSDN 博客上找到该脚本http://blogs.msdn.com/astebner/archive/2006/08/12/696833.aspx
There's an interesting article about it on CodeProject and some good answers there also (which is where I found Aaron's article). http://www.codeproject.com/KB/install/Installation.aspx
CodeProject 上有一篇关于它的有趣文章,那里也有一些很好的答案(我在那里找到了 Aaron 的文章)。 http://www.codeproject.com/KB/install/Installation.aspx
Finally, there's also some other similar questions on StackOverflow
最后,StackOverflow上还有一些其他类似的问题
How to run executable at end of Setup Project?
How to automatically start my application when my setup is done in C# setup project
回答by bendytree
Here's how to make your application launch after install (using VS2010):
以下是在安装后启动应用程序的方法(使用 VS2010):
Assuming you already have 2 projects like: MyApp.Applicationand MyApp.Installer.
假设您已经有 2 个项目,例如:MyApp.Application和MyApp.Installer.
- Right-click the project for
MyApp.Applicationand chooseAdd>New Item...>Installer Class(name it whatever you want) - Right-click the new Installer class & choose
View Code Override the
Commitmethod like this:public override void Commit(IDictionary savedState) { base.Commit(savedState); Directory.SetCurrentDirectory(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)); Process.Start(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\MyApp.exe"); }Update
MyApp.exeto use the name of your application- Right-click your
MyApp.Installerproject & chooseView>Custom Actions - Right-click the
Commitfolder & chooseAdd custom action - Choose
Application Folder>OK>OK
- 右键单击项目
MyApp.Application并选择Add>New Item...>Installer Class(随意命名) - 右键单击新的安装程序类并选择
View Code Commit像这样覆盖方法:public override void Commit(IDictionary savedState) { base.Commit(savedState); Directory.SetCurrentDirectory(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)); Process.Start(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\MyApp.exe"); }更新
MyApp.exe以使用您的应用程序名称- 右键单击您的
MyApp.Installer项目并选择View>Custom Actions - 右键单击
Commit文件夹并选择Add custom action - 选择
Application Folder>OK>OK

