使用Mage创建的ClickOnce应用程序未显示控制面板添加或删除程序中Mage命令行参数中指定的图标。
我读了一些博客,比如:
Application icon is not displayed in Add/Remove Programs dialog
Missing Icon in Add/Remove Programs for ClickOnce Application
如何在不编辑注册表项的情况下实现此目的?有可能吗?
答案 0 :(得分: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
}
}
}