AppDomain.CurrentDomain.SetupInformation.ActivationArguments 为一个 ClickOnce 应用程序返回 null 而不是另一个 [英] AppDomain.CurrentDomain.SetupInformation.ActivationArguments returns null for one ClickOnce application but not the other

查看:24
本文介绍了AppDomain.CurrentDomain.SetupInformation.ActivationArguments 为一个 ClickOnce 应用程序返回 null 而不是另一个的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个 WinForm ClickOnce 应用程序,最初使用 Visual Studio Express 2008 (C#) 开发,现在使用 VS Express 2013 进行维护.两者都针对 .NET Framework 4 Client Profile.

I have two WinForm ClickOnce applications initially developed with Visual Studio Express 2008 (C#) and now maintained using VS Express 2013. Both target the .NET Framework 4 Client Profile.

请考虑下面的代码,其中我尝试通过在 InitializeComponent() 之后插入一行代码并在 VS 中单击启动"来运行和调试应用程序来获取 ActivationArguments:

Please consider the code below where I try to get ActivationArguments by inserting the one line of code after InitializeComponent() and clicking Start in VS to run and debug the application:

public Form1()
{ 
    InitializeComponent();                
    ActivationArguments actArgs = AppDomain.CurrentDomain.SetupInformation.ActivationArguments;
    etc...
}

我不明白为什么一个应用程序为 ActivationArguments 返回 null 而另一个应用程序返回预期的对象.两者都是简单的 WinForm 应用程序,简单的 C#,相同的部署设置,没什么特别的.目标是最终获得 ActivationData,但我首先需要一个 ActivationArguments 对象才能到达那里.

I'm stumped as to why one application returns null for ActivationArguments while the other returns the expected object. Both are straightforward WinForm applications, straightforward C#, same deployment settings, nothing fancy. The goal is to eventually get ActivationData but I first need an ActivationArguments object to get there.

有什么想法吗?

推荐答案

以下内容适用于 C# WinForms App .Net 4.5,该应用程序将 ClickOnce Publishing 用于设置为..available offline.."的应用程序在项目的发布设置中.

The following applies to a C# WinForms App .Net 4.5 that uses ClickOnce Publishing for an application that is set to be "..available offline as well.." in the Publish Settings of the project.

1) 在项目设置中指定的命令行参数或从控制台传递的命令行参数可以通过将 args 添加到 main() 来在 program.cs 中读取

1) CommandLine arguments specified in the Project Settings or passed from a console can be either read in program.cs by adding args to the main()

static void Main(string[] args) // in program.cs, args[0] is first argument

或通过使用

string[] args = Environment.GetCommandLineArgs(); // in Form1.cs e.g. in Form1_Load, args[1] is first argument

2) 例如传递的命令行参数双击资源管理器/桌面中的关联文件可以这样读取:

2) CommandLine arguments passed by e.g. double clicking an associated file in Explorer/Desktop can be read like this:

using System.Deployment.Application;

// e.g. in Form1_Load
if (ApplicationDeployment.IsNetworkDeployed)
{
    string[] activationData = AppDomain.CurrentDomain.SetupInformation.ActivationArguments.ActivationData;
    if (activationData != null && activationData.Length > 0)
    {
        string[] args = activationData[0].Split(new char[] { ',' });
        if (args.Length > 0)
        {
            // args[0] is first argument
        }
    }
}

这篇关于AppDomain.CurrentDomain.SetupInformation.ActivationArguments 为一个 ClickOnce 应用程序返回 null 而不是另一个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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