我可以从应用程序内部获取 ClickOnce 发布的产品名称吗?

问题描述 投票:0回答:4

我的 ClickOnce 发布名称与程序集名称不同。出于讨论目的,它是“App 6.0”。我在项目的属性中设置了它。有没有办法从程序内部获取这个值?

c# installation clickonce
4个回答
5
投票

添加对

Microsoft.Build.Tasks.v4.0.dll
的引用,然后运行以下命令:

if (null != AppDomain.CurrentDomain.ActivationContext)
{
    DeployManifest manifest;
    using (MemoryStream stream = new MemoryStream(AppDomain.CurrentDomain.ActivationContext.DeploymentManifestBytes))
    {
        manifest = (DeployManifest)ManifestReader.ReadManifest("Deployment", stream, true);
    }
    // manifest.Product has the name you want
}
else
{
   // not deployed
}

DeployManifest 还可以提供清单中的其他有用信息,例如 Publisher 或 SupportUrl。


2
投票

答案可以在ClickOnce Run at Startup中找到。本质上,您使用 InPlaceHostingManager 获取 ClickOnce 清单并读取它。它是一个异步方法,这让我感到烦恼,但这是迄今为止唯一有效的方法。非常感谢简化。请参阅网页以获取 DeploymentDescription 的说明。

var inPlaceHostingManager = new InPlaceHostingManager(ApplicationDeployment.CurrentDeployment.UpdateLocation, false);
inPlaceHostingManager.GetManifestCompleted += ((sender, e) =>
{
    try
    {
        var deploymentDescription = new DeploymentDescription(e.DeploymentManifest);
        string productName = deploymentDescription.Product;
        ***DoSomethingToYour(productName);***

        // - use this later -
        //var commandBuilder = new StartMenuCommandBuilder(deploymentDescription);
        //string startMenuCommand = commandBuilder.Command;
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message + Environment.NewLine + ex.StackTrace);
    }
});

0
投票

ApplicationDeployment.UpdatedApplicationFullName 属性


0
投票

这些答案都不适用于 .net 7。请注意

© www.soinside.com 2019 - 2024. All rights reserved.