Search code examples
c#installationclickonce

Can I obtain the ClickOnce published Product Name from inside the application?


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?


Solution

  • 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);
        }
    });