C# 在 VS2010 安装项目中为快捷方式设置正确的图标
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9014337/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Setting correct icon for Shortcut in VS2010 Setup Project
提问by BlueChippy
I have a small app with a setup project. If I create a shortcut to my Primary Output, then this gets a standard Win7 icon and not the icon specified in my exe's Application Icon?
我有一个带有安装项目的小应用程序。如果我为我的主输出创建一个快捷方式,那么这会得到一个标准的 Win7 图标,而不是我的 exe 的应用程序图标中指定的图标?
Whats the best way to make sure my desktop shortcut icon is the same icon as my exe? e.g. If I change the exe's icon then I'd like the Setup icon to change as well.
确保我的桌面快捷方式图标与我的 exe 图标相同的最佳方法是什么?例如,如果我更改 exe 的图标,那么我希望设置图标也更改。
采纳答案by Gert Arnold
If you set the icon for the shortcut you can set a primary output as source. In the file system editor of the setup project, click on the "(Icon)" combobox in the properties pane of the shortcut, then option "(Browse...)", button "Browse...". You'll see this:
如果您设置快捷方式的图标,您可以将主要输出设置为源。在安装项目的文件系统编辑器中,单击快捷方式属性窗格中的“(图标)”组合框,然后选择“(浏览...)”,按钮“浏览...”。你会看到这个:


Then add output and select the primary output of the exe.
然后添加输出并选择exe的主要输出。
回答by Mike Bethany
To add to Gert's answer: make sure you build your project first. Otherwise the setup app will not see the icon.
添加到 Gert 的答案:确保首先构建您的项目。否则设置应用程序将看不到该图标。
回答by user16719
You can add an icon from your target.exe file to the shortcut... in File System On Target Machine, browse to the shortcut in the folder you want to add the icon to (User's Desktop,etc). Right click the shortcut and select Properties Window. You'll see an Icon line... click it, select Browse, then browse to Application Folder/yourExe.exe (change from ICON to Exe files) and say OK. It will show you the icon from yourExe.exe that it has selected, say OK. You basically have to do the same thing for your Add/Remove Icon (appears in Control Panel/Uninstall)... properties page for your setup project. You have to do it for all shortcuts in different folders (User's Desktop, User's Startup, etc.) All icons good now!
您可以将 target.exe 文件中的图标添加到快捷方式...在目标机器上的文件系统中,浏览到您要将图标添加到的文件夹中的快捷方式(用户桌面等)。右键单击快捷方式并选择“属性窗口”。您将看到一个图标行...单击它,选择浏览,然后浏览到应用程序文件夹/yourExe.exe(从 ICON 更改为 Exe 文件)并说 OK。它将显示您选择的 yourExe.exe 图标,说 OK。您基本上必须为您的安装项目的添加/删除图标(出现在控制面板/卸载中)...属性页面做同样的事情。您必须为不同文件夹(用户桌面、用户启动等)中的所有快捷方式执行此操作。现在所有图标都很好!
回答by Gian C.
Very simple way using IWshShortcut (works in .net 2 too):
使用 IWshShortcut 的非常简单的方法(也适用于 .net 2):
WshRuntimeLibrary.IWshShortcut MyShortcut = (IWshRuntimeLibrary.IWshShortcut)WshShell.CreateShortcut(fullPathLnk);
string iconLoc = MyShortcut.IconLocation; // <- example: "c:\icon.ico,0"
I use to check if iconLoc still exists, fix if not, you can use to find and read icon file, etc etc
我用来检查 iconLoc 是否仍然存在,如果不存在则修复,您可以用来查找和读取图标文件等

