2011-09-28 70 views
3

我有一个VB.NET应用程序,它采用命令行参数。ClickOnce应用程序将不接受命令行参数

它调试时提供的罚款,我关闭Visual Studio的ClickOnce安全设置。

当我尝试通过ClickOnce在计算机上安装应用程序并尝试使用参数运行应用程序时,会发生此问题。发生这种情况时我会发生崩溃(哦,不!)。

解决此问题的方法是:将文件从最新版本的发布文件夹移至计算机的C:驱动器,并从.exe中删除“.deploy”。从C:驱动器运行应用程序,它将处理参数就好了。

有没有更好的方式来得到这个工作比我上面的解决方法?

谢谢!

+0

请问[本文](http://robindotnet.wordpress.com/2010/03/21/how-to-pass-arguments-to-an-offline-clickonce-application/)有帮助吗? –

回答

3

“命令行参数”仅适用于从URL运行的ClickOnce应用程序。

例如,这是你应该如何启动应用程序,以附加一些运行时参数:

http://myserver/install/MyApplication.application?argument1=value1&argument2=value2

我有,我用它来解析的ClickOnce下面的C#代码激活的URL和命令行参数的一致好评:

public static string[] GetArguments() 
{ 
    var commandLineArgs = new List<string>(); 
    string startupUrl = String.Empty; 

    if (ApplicationDeployment.IsNetworkDeployed && 
     ApplicationDeployment.CurrentDeployment.ActivationUri != null) 
    { 
     // Add the EXE name at the front 
     commandLineArgs.Add(Environment.GetCommandLineArgs()[0]); 

     // Get the query portion of the URI, also decode out any escaped sequences 
     startupUrl = ApplicationDeployment.CurrentDeployment.ActivationUri.ToString(); 
     var query = ApplicationDeployment.CurrentDeployment.ActivationUri.Query; 
     if (!string.IsNullOrEmpty(query) && query.StartsWith("?")) 
     { 
      // Split by the ampersands, a append a "-" for use with splitting functions 
      string[] arguments = query.Substring(1).Split(new[] { '&' }, StringSplitOptions.RemoveEmptyEntries).Select(a => String.Format("-{0}", HttpUtility.UrlDecode(a))).ToArray(); 

      // Now add the parsed argument components 
      commandLineArgs.AddRange(arguments); 
     } 
    } 
    else 
    { 
     commandLineArgs = Environment.GetCommandLineArgs().ToList(); 
    } 

    // Also tack on any activation args at the back 
    var activationArgs = AppDomain.CurrentDomain.SetupInformation.ActivationArguments; 
    if (activationArgs != null && activationArgs.ActivationData.EmptyIfNull().Any()) 
    { 
     commandLineArgs.AddRange(activationArgs.ActivationData.Where(d => d != startupUrl).Select((s, i) => String.Format("-in{1}:\"{0}\"", s, i == 0 ? String.Empty : i.ToString()))); 
    } 

    return commandLineArgs.ToArray(); 
} 

这样的,我的主要功能是这样的:

/// <summary> 
    /// The main entry point for the application. 
    /// </summary> 
    [STAThread] 
    static void Main() 
    { 
     var commandLine = GetArguments(); 
     var args = commandLine.ParseArgs(); 

     // Run app 
    }