.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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 10:26:53  来源:igfitidea点击:

How do I launch an application after install in a Visual Studio Setup Project

.netvisual-studio-2008installation

提问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

I have used a custom action in VS 2005. Not sure if this is enhanced in VS 2008.

我在VS 2005 中使用了自定义操作。不确定这是否在 VS 2008 中得到增强。

回答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

在 C# 设置项目中完成设置后如何自动启动我的应用程序

回答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.ApplicationMyApp.Installer.

  1. Right-click the project for MyApp.Applicationand choose Add> New Item...> Installer Class(name it whatever you want)
  2. Right-click the new Installer class & choose View Code
  3. 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");
    }
    
  4. Update MyApp.exeto use the name of your application

  5. Right-click your MyApp.Installerproject & choose View> Custom Actions
  6. Right-click the Commitfolder & choose Add custom action
  7. Choose Application Folder> OK> OK
  1. 右键单击项目MyApp.Application并选择Add> New Item...> Installer Class(随意命名)
  2. 右键单击新的安装程序类并选择 View Code
  3. 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");
    }
    
  4. 更新MyApp.exe以使用您的应用程序名称

  5. 右键单击您的MyApp.Installer项目并选择View>Custom Actions
  6. 右键单击Commit文件夹并选择Add custom action
  7. 选择Application Folder> OK>OK

References:

参考: