2011-09-28 47 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 
    } 
相關問題