在不运行的情况下安装 ClickOnce [英] Install ClickOnce without running

查看:31
本文介绍了在不运行的情况下安装 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆