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

发布于 2024-11-05 14:04:11 字数 84 浏览 0 评论 0原文

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

I have a ClickOnce Publish Name that is different from the assembly name. For discussion purposes, it is "App 6.0". I set it in the Properties for my project. Is there any way to get this value from inside the program?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

想挽留 2024-11-12 14:04:11

添加对 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。

Add a reference to Microsoft.Build.Tasks.v4.0.dll, then run this:

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
}

The DeployManifest can also provide other useful info from your manifest, like Publisher or SupportUrl.

酷遇一生 2024-11-12 14:04:11

答案可以在ClickOnce Run at Startup<中找到/a>。本质上,您使用 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);
    }
});

The answer can be found in ClickOnce Run at Startup. Essentially, you use InPlaceHostingManager to get the ClickOnce manifest and read it. It bugs me that it is an asynchronous method, but this is the only thing that has worked thus far. Simplifications are much appreciated. See the webpage for a description of 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);
    }
});
话少情深 2024-11-12 14:04:11

ApplicationDeployment.UpdatedApplicationFullName 属性

ApplicationDeployment.UpdatedApplicationFullName Property

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文