我们的用户从开始菜单/桌面快捷方式运行我们的 ClickOnce WPF应用程序。当应用程序每次启动时,我们都需要获取最初下载它的 URL。我尝试使用 ActivationUri,但这仅在直接从网站 setup.exe 而不是桌面/开始菜单快捷方式运行时才有效:
string activationUri = "???";
try
{
if (System.Deployment.Application.ApplicationDeployment.CurrentDeployment == null)
{
activationUri = "currentDeployment is null";
}
else if (System.Deployment.Application.ApplicationDeployment.CurrentDeployment.ActivationUri == null)
{
activationUri = "deployment not null but uri is";
}
else if (System.Deployment.Application.ApplicationDeployment.CurrentDeployment.ActivationUri != null)
{
activationUri =
System.Deployment.Application.ApplicationDeployment.CurrentDeployment.ActivationUri.AbsoluteUri;
}
}
catch (Exception ex)
{
activationUri = ex.Message;
//Error getting the URL so put question mark
}
MessageBox.Show(activationUri);
从设置(从网站)运行时,我会得到 URL,每隔一次我会得到“部署不为空,但 URI 是”。