安装ClickOnce而不运行

安装ClickOnce而不运行

本文介绍了安装ClickOnce而不运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

安装ClickOnce应用程序后,该程序将在安装后运行。我可以使用安装程序和部署项目并创建一个安装程序,但是我希望能够安装而不使用运行?

When you install a ClickOnce application, the program runs after the install. Is it possible to install without running?

使用ClickOnce。

I know I can use a setup and deployment project and create an installer, but I'd prefer to use ClickOnce.

推荐答案

我想你可以伪造它。引入一个IsInstalled布尔属性,默认为false。然后在Program.cs中,将Main()方法更改为如下所示:

I guess you could fake it. Introduce an "IsInstalled" boolean property, defaulted to false. Then in Program.cs, change your Main() method to look like this:

[STAThread]
static void Main()
{
    Application.EnableVisualStyles();
    Application.SetCompatibleTextRenderingDefault(false);

    if (!Properties.Settings.Default.IsInstalled)
    {
        Properties.Settings.Default.IsInstalled = true;
        Properties.Settings.Default.Save();

        MessageBox.Show("Install Complete");
        return;
    }

    Application.Run(new Form1());
}

所以现在当第一次安装该应用程序时,它检查该属性并简单显示一个消息给用户然后退出。

So now when the app is first installed, it checks that property and simply displays a message to the user and then quits.

如果您想要棘手,那么您可以查看解析部署的激活URI,并有一个URI参数,指定是否程序应该首先安装或者只是静默地关闭。

If you wanted to get tricky then you could look at parsing the Activation URI for the deployment and have a URI parameter which specifies whether the program should run when it's first installed or just close silently.

这篇关于安装ClickOnce而不运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-27 23:51