且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在不运行的情况下安装 ClickOnce

更新时间:2022-05-11 01:38:35

我猜你可以伪造它.引入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.