"添加或删除程序"中ClickOnce应用程序的自定义图标

Rag*_*ghu 14 clickonce wix mage

使用Mage创建的ClickOnce应用程序未显示控制面板" 添加或删除程序"中为Mage命令行参数指定的图标.

我读了一些博客,比如:

如何在不编辑注册表项的情况下实现此目的?可能吗?

Rob*_*Net 17

没有编辑注册表就无法做到这一点,但你可以通过编程方式完成.您必须确保该部署中包含该图标.我们将程序集描述设置为与产品名称相同的字符串,因此我们可以通过搜索程序集描述来查看正确应用程序的卸载字符串.这样,我们就不必在此代码中对产品名称进行硬编码.

        private static void SetAddRemoveProgramsIcon()
    {
        //only run if deployed 
        if (System.Deployment.Application.ApplicationDeployment.IsNetworkDeployed
             && ApplicationDeployment.CurrentDeployment.IsFirstRun)
        {
            try
            {
                Assembly code = Assembly.GetExecutingAssembly();
                AssemblyDescriptionAttribute asdescription =
                    (AssemblyDescriptionAttribute)Attribute.GetCustomAttribute(code, typeof(AssemblyDescriptionAttribute));
                string assemblyDescription = asdescription.Description;

                //the icon is included in this program
                string iconSourcePath = Path.Combine(System.Windows.Forms.Application.StartupPath, "youriconfile.ico");

                if (!File.Exists(iconSourcePath))
                    return;

                RegistryKey myUninstallKey = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Uninstall");
                string[] mySubKeyNames = myUninstallKey.GetSubKeyNames();
                for (int i = 0; i < mySubKeyNames.Length; i++)
                {
                    RegistryKey myKey = myUninstallKey.OpenSubKey(mySubKeyNames[i], true);
                    object myValue = myKey.GetValue("DisplayName");
                    if (myValue != null && myValue.ToString() == assemblyDescription)
                    {
                        myKey.SetValue("DisplayIcon", iconSourcePath);
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                //log an error
            }
        }
    }
Run Code Online (Sandbox Code Playgroud)