我有一个采用命令行参数的 VB.NET 应用程序。
如果我关闭 Visual Studio 的 ClickOnce 安全设置,调试时它可以正常工作。
当我尝试通过 ClickOnce 在计算机上安装应用程序并尝试使用参数运行它时,会出现此问题。当这种情况发生时我会崩溃(哦不!)。
此问题有一个解决方法:将文件从最新版本的发布文件夹移动到计算机的 C: 驱动器,并从 .exe 中删除“.deploy”。从 C: 驱动器运行应用程序,它将很好地处理参数。
有没有比我上面的解决方法更好的方法来让它发挥作用?
Thanks!
“命令行参数”仅适用于从 URL 运行的 ClickOnce 应用程序。
例如,您应该这样启动应用程序以附加一些运行时参数:
我有以下 C# 代码,用于解析 ClickOnce 激活 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
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)