.net 如何将命令行参数传递给 ClickOnce 应用程序?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/429351/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 10:57:28  来源:igfitidea点击:

How does one pass command line argument to a ClickOnce application?

.netclickonce

提问by Szymon Rozga

I have a Clickonce application that is launched from the start menu (local). I would like to be able to specify a parameter so that the application can load certain data. The application lives on a fileshare and will be launched using the URL only once (like described here on MSDN). This implies that the method describe in this link will not work; users will be launching the application using an .appref-ms shortcut in the Start Menu.

我有一个从开始菜单(本地)启动的 Clickonce 应用程序。我希望能够指定一个参数,以便应用程序可以加载某些数据。该应用程序存在于文件共享中,并且将仅使用 URL 启动一次(如MSDN 上的此处所述)。这意味着此链接中描述的方法将不起作用;用户将使用开始菜单中的 .appref-ms 快捷方式启动应用程序。

I haven't been able to find a solution. Is it possible to somehow pass a parameter into the click once application? If so, how? If not, what are some alternatives?

我一直无法找到解决方案。是否有可能以某种方式将参数传递到 click once 应用程序中?如果是这样,如何?如果没有,有哪些替代方案?

采纳答案by joshua.ewer

Since you get to the deployment manifest via a Url, you can pass all of that information via the query string (e.g. http://clickonce.example.com/shell.application?p1=this&p2=that)

由于您通过 Url 访问部署清单,因此您可以通过查询字符串(例如http://clickonce.example.com/shell.application?p1=this&p2=that

I was going to type out the steps, then googled and found this blogthat basically lists out all the steps. I've done something similar in one instance with no issues. The only slightly difficult thing is that you have to re-mage after setting things up, but if you got it to deploy in the first place, you already know how to set things up.

我打算把步骤写出来,然后用谷歌搜索,发现这个博客基本上列出了所有的步骤。我在一个实例中做过类似的事情,没有任何问题。唯一稍微有点困难的是你必须在设置后重新法师,但是如果你首先部署它,你已经知道如何设置。

Good luck!

祝你好运!

回答by deadlydog

All of the answers here only apply to Online ClickOnce applications. This MSDN Forum postand this blog postdiscuss some ways to do it for Offline ClickOnce applications.

此处的所有答案仅适用于 Online ClickOnce 应用程序。 这篇 MSDN 论坛帖子这篇博文讨论了为离线 ClickOnce 应用程序执行此操作的一些方法。

回答by Orion Edwards

Perhaps you could pass a parameter on the URL the first time, and have the app take notice of that, and write the parameters to a config file, or environment variables or somesuch.

也许您可以在第一次在 URL 上传递一个参数,并让应用程序注意到这一点,并将参数写入配置文件或环境变量等。

On subsequent runs, load from the config file

在后续运行中,从配置文件加载

回答by Magnus Johansson

You pass the parameters as a query string and use HttpUtility.ParseQueryString, as discussed in this MSDN article.

您将参数作为查询字符串传递并使用 HttpUtility.ParseQueryString,如这篇 MSDN 文章 中所述